Introduce {,MAIN_}EXIT_WITH_ERROR macros for exitting with an error

This commit is contained in:
Benjamin Loison 2023-01-22 15:17:14 +01:00
parent d34fade0cd
commit 9d40fef429
Signed by: Benjamin_Loison
SSH Key Fingerprint: SHA256:BtnEgYTlHdOg1u+RmYcDE0mnfz1rhv5dSbQ2gyxW8B8

View File

@ -36,6 +36,9 @@ bool doesFileExist(string filePath),
#define DEFAULT_THREAD_ID 0
#define MAIN_PRINT(x) THREAD_PRINT(DEFAULT_THREAD_ID, x)
#define EXIT_WITH_ERROR(x) { PRINT(x); exit(EXIT_FAILURE); }
#define MAIN_EXIT_WITH_ERROR(x) { MAIN_PRINT(x); exit(EXIT_FAILURE); }
mutex printMutex,
channelsAlreadyTreatedAndToTreatMutex,
quotaMutex;
@ -84,14 +87,12 @@ int main(int argc, char *argv[])
}
else
{
MAIN_PRINT("YouTube operational API instance URL missing!")
exit(EXIT_FAILURE);
MAIN_EXIT_WITH_ERROR("YouTube operational API instance URL missing!")
}
}
else
{
MAIN_PRINT("Unrecognized parameter " << argvStr)
exit(EXIT_FAILURE);
MAIN_EXIT_WITH_ERROR("Unrecognized parameter " << argvStr)
}
}
@ -273,8 +274,7 @@ void treatChannelOrVideo(unsigned short threadId, bool isChannel, string id, str
json data = getJson(threadId, "playlistItems?part=snippet,contentDetails,status&playlistId=" + playlistToTreat + "&maxResults=50&pageToken=" + pageToken, true, channelToTreat, returnErrorIfPlaylistNotFound);
if(data.contains("error"))
{
PRINT("Not listing comments on videos, as `playlistItems` hasn't found the `uploads` playlist!")
exit(EXIT_FAILURE);
EXIT_WITH_ERROR("Not listing comments on videos, as `playlistItems` hasn't found the `uploads` playlist!")
}
json items = data["items"];
for(const auto& item : items)
@ -302,8 +302,7 @@ void treatChannelOrVideo(unsigned short threadId, bool isChannel, string id, str
}
else //if(videoCount >= 20000)
{
PRINT("The videos count of the channel exceeds the supported 20,000 limit!")
exit(EXIT_FAILURE);
EXIT_WITH_ERROR("The videos count of the channel exceeds the supported 20,000 limit!")
}
}
}
@ -521,8 +520,7 @@ void treatChannelOrVideo(unsigned short threadId, bool isChannel, string id, str
// We verify that we don't skip any message by verifying that the first message was already treated if we already treated some messages.
if(!messageIds.empty() && messageIds.find(firstMessageId) == messageIds.end())
{
PRINT("The verification that we don't skip any message failed!")
exit(EXIT_FAILURE);
EXIT_WITH_ERROR("The verification that we don't skip any message failed!")
}
for(const auto& message : snippet)
{
@ -698,8 +696,7 @@ json getJson(unsigned short threadId, string url, bool usingYoutubeDataApiv3, st
}
catch (json::parse_error& ex)
{
PRINT("Parse error for " << finalUrl << ", as got: " << content << " !")
exit(EXIT_FAILURE);
EXIT_WITH_ERROR("Parse error for " << finalUrl << ", as got: " << content << " !")
}
if(data.contains("error"))