From 4fbe638adf39f413e8fb5a20e4de6833a8bbbdd2 Mon Sep 17 00:00:00 2001 From: John Knox Date: Tue, 12 Jun 2018 03:43:05 -0700 Subject: [PATCH] Silence expected error logs Summary: When an app with sonar is run for the first time, the necessary files don't exist. This is expected, so don't output an error, only error if they do exist but there's some other problem. Reviewed By: emilsjolander Differential Revision: D8350995 fbshipit-source-id: ff0a4f0e7a73848f6172c6108a0caee6efb43553 --- xplat/Sonar/SonarWebSocketImpl.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/xplat/Sonar/SonarWebSocketImpl.cpp b/xplat/Sonar/SonarWebSocketImpl.cpp index 26419b99d..cc81efcc4 100644 --- a/xplat/Sonar/SonarWebSocketImpl.cpp +++ b/xplat/Sonar/SonarWebSocketImpl.cpp @@ -42,6 +42,8 @@ static constexpr int insecurePort = 8089; namespace facebook { namespace sonar { +bool fileExists(std::string fileName); + class ConnectionEvents : public rsocket::RSocketConnectionEvents { private: SonarWebSocketImpl* websocket_; @@ -249,6 +251,9 @@ void SonarWebSocketImpl::requestSignedCertFromSonar() { } std::string SonarWebSocketImpl::loadStringFromFile(std::string fileName) { + if (!fileExists(fileName)) { + return ""; + } std::stringstream buffer; std::ifstream stream; std::string line; @@ -283,5 +288,10 @@ bool SonarWebSocketImpl::ensureSonarDirExists() { } } +bool fileExists(std::string fileName) { + struct stat buffer; + return stat(fileName.c_str(), &buffer) == 0; +} + } // namespace sonar } // namespace facebook