diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-05-14 16:48:20 +0200 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-05-15 16:46:45 +0200 |
commit | 0fd32f8b9d707d807c236156de12118b0a695d69 (patch) | |
tree | 08181c9b2d429ab896cee10302630f6972aae64a /src/buildtool/serve_api/serve_service/target_utils.cpp | |
parent | 2bcbeb55f45a6c5aa193fab06f301f7231d5f16c (diff) | |
download | justbuild-0fd32f8b9d707d807c236156de12118b0a695d69.tar.gz |
logging: Do not make assumptions in emit calls
The Emit method of the Logger class, when called with a string as
second argument, expects it to be a format string. It should be
considered a programming error to pass a string variable as that
argument without knowing for certain that it does not contain any
format escape character ('{', '}'); instead, one should be
conservative and use the blind format string "{}" as second
argument and pass the unknown string variable as third argument.
Diffstat (limited to 'src/buildtool/serve_api/serve_service/target_utils.cpp')
-rw-r--r-- | src/buildtool/serve_api/serve_service/target_utils.cpp | 43 |
1 files changed, 20 insertions, 23 deletions
diff --git a/src/buildtool/serve_api/serve_service/target_utils.cpp b/src/buildtool/serve_api/serve_service/target_utils.cpp index c9268f63..7a94c9ee 100644 --- a/src/buildtool/serve_api/serve_service/target_utils.cpp +++ b/src/buildtool/serve_api/serve_service/target_utils.cpp @@ -38,13 +38,12 @@ auto IsTreeInRepo(std::string const& tree_id, auto wrapped_logger = std::make_shared<GitRepo::anon_logger_t>( [logger, repo_path, tree_id](auto const& msg, bool fatal) { if (fatal) { - auto err = fmt::format( - "ServeTarget: While checking existence of tree {} " - "in repository {}:\n{}", - tree_id, - repo_path.string(), - msg); - logger->Emit(LogLevel::Info, err); + logger->Emit(LogLevel::Info, + "ServeTarget: While checking existence of " + "tree {} in repository {}:\n{}", + tree_id, + repo_path.string(), + msg); } }); if (auto res = repo->CheckTreeExists(tree_id, wrapped_logger)) { @@ -238,13 +237,12 @@ auto GetBlobContent(std::filesystem::path const& repo_path, auto wrapped_logger = std::make_shared<GitRepo::anon_logger_t>( [logger, repo_path, tree_id](auto const& msg, bool fatal) { if (fatal) { - auto err = fmt::format( - "ServeTargetVariables: While checking if tree {} " - "exists in repository {}:\n{}", - tree_id, - repo_path.string(), - msg); - logger->Emit(LogLevel::Debug, err); + logger->Emit(LogLevel::Debug, + "ServeTargetVariables: While checking if " + "tree {} exists in repository {}:\n{}", + tree_id, + repo_path.string(), + msg); } }); if (repo->CheckTreeExists(tree_id, wrapped_logger) == true) { @@ -255,26 +253,25 @@ auto GetBlobContent(std::filesystem::path const& repo_path, [logger, repo_path, blob_id = entry_info->id]( auto const& msg, bool fatal) { if (fatal) { - auto err = fmt::format( + logger->Emit( + LogLevel::Debug, "ServeTargetVariables: While retrieving " "blob {} from repository {}:\n{}", blob_id, repo_path.string(), msg); - logger->Emit(LogLevel::Debug, err); } }); // get blob content return repo->TryReadBlob(entry_info->id, wrapped_logger); } // trace failure to get entry - auto err = fmt::format( - "ServeTargetVariables: Failed to retrieve entry {} in " - "tree {} from repository {}", - rel_path, - tree_id, - repo_path.string()); - logger->Emit(LogLevel::Debug, err); + logger->Emit(LogLevel::Debug, + "ServeTargetVariables: Failed to retrieve entry " + "{} in tree {} from repository {}", + rel_path, + tree_id, + repo_path.string()); return std::pair(false, std::nullopt); // could not read blob } } |