Skip to content

Commit 2d87b6a

Browse files
committed
Change tfm::format for no stream version to tfm::strformat
The linter is confused by the overload of tfm::format to return a string instead of the first argument being a stream. Using a different function name solves the problem.
1 parent 71e99a7 commit 2d87b6a

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

src/gridcoin/scraper/http.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ void Http::Download(
210210
ScopedFile fp(fsbridge::fopen(destination, "wb"), &fclose);
211211
if (!fp)
212212
throw std::runtime_error(
213-
tfm::format("Error opening target %s: %s (%d)", destination, strerror(errno), errno));
213+
tfm::strformat("Error opening target %s: %s (%d)", destination, strerror(errno), errno));
214214

215215
std::string buffer;
216216
ScopedCurl curl = GetContext();
@@ -221,7 +221,7 @@ void Http::Download(
221221

222222
CURLcode res = curl_easy_perform(curl.get());
223223
if (res > 0)
224-
throw std::runtime_error(tfm::format("Failed to download file %s: %s", url, curl_easy_strerror(res)));
224+
throw std::runtime_error(tfm::strformat("Failed to download file %s: %s", url, curl_easy_strerror(res)));
225225
}
226226

227227
std::string Http::GetEtag(
@@ -247,7 +247,7 @@ std::string Http::GetEtag(
247247
curl_slist_free_all(headers);
248248

249249
if (res > 0)
250-
throw std::runtime_error(tfm::format("Failed to get ETag for URL %s: %s", url, curl_easy_strerror(res)));
250+
throw std::runtime_error(tfm::strformat("Failed to get ETag for URL %s: %s", url, curl_easy_strerror(res)));
251251

252252
// Validate HTTP return code.
253253
long response_code;
@@ -291,7 +291,7 @@ std::string Http::GetLatestVersionResponse()
291291
CURLcode res = curl_easy_perform(curl.get());
292292

293293
if (res > 0)
294-
throw std::runtime_error(tfm::format("Failed to get version response from URL %s: %s",
294+
throw std::runtime_error(tfm::strformat("Failed to get version response from URL %s: %s",
295295
url, curl_easy_strerror(res)));
296296

297297
curl_slist_free_all(headers);
@@ -320,7 +320,7 @@ void Http::DownloadSnapshot()
320320
DownloadStatus.SetSnapshotDownloadFailed(true);
321321

322322
throw std::runtime_error(
323-
tfm::format("Snapshot Downloader: Error opening target %s: %s (%d)",
323+
tfm::strformat("Snapshot Downloader: Error opening target %s: %s (%d)",
324324
destination.string(), strerror(errno), errno));
325325
}
326326

@@ -374,7 +374,7 @@ void Http::DownloadSnapshot()
374374
{
375375
DownloadStatus.SetSnapshotDownloadFailed(true);
376376

377-
throw std::runtime_error(tfm::format("Snapshot Downloader: Failed to download file %s: %s",
377+
throw std::runtime_error(tfm::strformat("Snapshot Downloader: Failed to download file %s: %s",
378378
url, curl_easy_strerror(res)));
379379
}
380380
}
@@ -458,13 +458,13 @@ void Http::EvaluateResponse(int code, const std::string& url)
458458
code == 308)
459459
return;
460460
else if (code == 400)
461-
throw HttpException(tfm::format("Server returned a http code of Bad Request <url=%s, code=%d>", url, code));
461+
throw HttpException(tfm::strformat("Server returned a http code of Bad Request <url=%s, code=%d>", url, code));
462462
else if (code == 401)
463-
throw HttpException(tfm::format("Server returned a http code of Unauthorized <url=%s, code=%d>", url, code));
463+
throw HttpException(tfm::strformat("Server returned a http code of Unauthorized <url=%s, code=%d>", url, code));
464464
else if (code == 403)
465-
throw HttpException(tfm::format("Server returned a http code of Forbidden <url=%s, code=%d>", url, code));
465+
throw HttpException(tfm::strformat("Server returned a http code of Forbidden <url=%s, code=%d>", url, code));
466466
else if (code == 404)
467-
throw HttpException(tfm::format("Server returned a http code of Not Found <url=%s, code=%d>", url, code));
467+
throw HttpException(tfm::strformat("Server returned a http code of Not Found <url=%s, code=%d>", url, code));
468468

469-
throw HttpException(tfm::format("Server returned a http code <url=%s, code=%d>", url, code));
469+
throw HttpException(tfm::strformat("Server returned a http code <url=%s, code=%d>", url, code));
470470
}

src/gridcoin/scraper/scraper.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,7 @@ void _log(logattribute eType, const std::string& sCall, const std::string& sMess
10141014
return;
10151015
}
10161016

1017-
sOut = tfm::format("%s [%s] <%s> : %s", DateTimeStrFormat("%x %H:%M:%S", GetAdjustedTime()), sType, sCall, sMessage);
1017+
sOut = tfm::strformat("%s [%s] <%s> : %s", DateTimeStrFormat("%x %H:%M:%S", GetAdjustedTime()), sType, sCall, sMessage);
10181018

10191019
// This snoops the SCRAPER category setting from the main logger, and uses it as a conditional for the scraper log output.
10201020
// Logs will be posted to the scraper log when the category is set OR it is not an INFO level... (i.e. critical, warning,
@@ -1320,7 +1320,7 @@ void ApplyCache(const std::string& key, T& result)
13201320
}
13211321
catch (const std::exception&)
13221322
{
1323-
_log(logattribute::ERR, "ScraperApplyAppCacheEntries", tfm::format("Ignoring bad AppCache entry for %s.", key));
1323+
_log(logattribute::ERR, "ScraperApplyAppCacheEntries", tfm::strformat("Ignoring bad AppCache entry for %s.", key));
13241324
}
13251325
}
13261326

@@ -2384,7 +2384,7 @@ EXCLUSIVE_LOCKS_REQUIRED(cs_TeamIDMap)
23842384

23852385
if (!ParseInt64(sTeamID, &nTeamID))
23862386
{
2387-
_log(logattribute::ERR, __func__, tfm::format("Ignoring bad team id for team %s.", sTeamName));
2387+
_log(logattribute::ERR, __func__, tfm::strformat("Ignoring bad team id for team %s.", sTeamName));
23882388
continue;
23892389
}
23902390

src/tinyformat.h

+8
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,14 @@ std::string format(const std::string &fmt, const Args&... args)
10611061
return oss.str();
10621062
}
10631063

1064+
// This is to make the linter happy because it the variadic script/python variadic checker does not deal with
1065+
// overloads.
1066+
template<typename... Args>
1067+
std::string strformat(const std::string &fmt, const Args&... args)
1068+
{
1069+
return format(fmt, args...);
1070+
}
1071+
10641072
} // namespace tinyformat
10651073

10661074
/** Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for details) */

test/lint/lint-format-strings.sh

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ FUNCTION_NAMES_AND_NUMBER_OF_LEADING_ARGUMENTS=(
1414
"FatalError,0"
1515
"fprintf,1"
1616
"tfm::format,1" # Assuming tfm::::format(std::ostream&, ...
17+
"tfm::strformat,0" # Assuming tfm::::strformat(fmt, ...
1718
"LogConnectFailure,1"
1819
"LogPrint,1"
1920
"LogPrintf,0"

0 commit comments

Comments
 (0)