Refactor warnings and errors (#1728)

* Remove `err` and `warn`, keep `errx` and `warnx`, using them in RGBGFX too

* Separate RGBGFX and RGBLINK warnings/errors from main options

* Separate `report` function into `error` and `fatal` messages

* Implicit newlines for most RGBASM errors
This commit is contained in:
Rangi
2025-07-08 12:58:23 -04:00
committed by GitHub
parent 991b74dd0d
commit 35962dedc4
39 changed files with 753 additions and 757 deletions

View File

@@ -3,8 +3,10 @@
#include "asm/main.hpp"
#include <algorithm>
#include <errno.h>
#include <limits.h>
#include <memory>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
@@ -109,6 +111,19 @@ static void printUsage() {
}
// LCOV_EXCL_STOP
[[gnu::format(printf, 1, 2), noreturn]]
static void fatalWithUsage(char const *fmt, ...) {
va_list ap;
fputs("FATAL: ", stderr);
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
putc('\n', stderr);
printUsage();
exit(1);
}
int main(int argc, char *argv[]) {
time_t now = time(nullptr);
// Support SOURCE_DATE_EPOCH for reproducible builds
@@ -198,7 +213,9 @@ int main(int argc, char *argv[]) {
dependFileName = "<stdout>";
}
if (dependFile == nullptr) {
err("Failed to open dependfile \"%s\"", dependFileName); // LCOV_EXCL_LINE
// LCOV_EXCL_START
errx("Failed to open dependfile \"%s\": %s", dependFileName, strerror(errno));
// LCOV_EXCL_STOP
}
break;
@@ -386,15 +403,9 @@ int main(int argc, char *argv[]) {
}
if (argc == musl_optind) {
fputs(
"FATAL: Please specify an input file (pass `-` to read from standard input)\n", stderr
);
printUsage();
exit(1);
fatalWithUsage("Please specify an input file (pass `-` to read from standard input)");
} else if (argc != musl_optind + 1) {
fputs("FATAL: More than one input file specified\n", stderr);
printUsage();
exit(1);
fatalWithUsage("More than one input file specified");
}
std::string mainFileName = argv[musl_optind];