]> git.hungrycats.org Git - bees/commitdiff
bees: write --show-config ROOT_PATH diagnostics straight to stderr scratch
authorZygo Blaxell <bees@furryterror.org>
Fri, 11 Sep 2026 15:09:21 +0000 (11:09 -0400)
committerZygo Blaxell <bees@furryterror.org>
Fri, 11 Sep 2026 15:09:21 +0000 (11:09 -0400)
The reason text is one string with embedded newlines, wrapped at 80
columns, written to cerr together with the specific failure in a single
insertion so the lines cannot interleave with other output.  Going to
stderr directly means the message is visible regardless of the log
configuration, which is the right behaviour for a command-line usage
error in bees_main.

Assisted-by: Claude-Code:claude-fable-5-1
src/bees.cc

index 19ca217d3c8e899f96f0df5f20e01f90b48d3640..ecd0bb31fdbcd5b9d462507d2ec69e503afe2d86 100644 (file)
@@ -149,29 +149,28 @@ wait_for_signals()
 }
 
 /// Why --show-config needs a real filesystem, for the diagnostics below.
-/// One log line per element, each under 80 columns.
-static const char *const show_config_root_reason[] = {
-       "--show-config ROOT_PATH needs the filesystem bees would run on, not a",
-       "configuration file:  the merged configuration depends on it (${ROOT},",
-       "${UUID}, ${LABEL} and ${FS_BYTES} interpolation, the local configuration",
-       "filename, and limits checked against the filesystem block size).",
-       "ROOT_PATH must be an existing directory that is the root of a mounted",
-       "btrfs filesystem, searchable by this user.",
-};
-
+/// Wrapped at 80 columns; written to stderr directly so it is visible
+/// regardless of the log configuration.
+static const char *const show_config_root_reason =
+       "--show-config ROOT_PATH needs the filesystem bees would run on, not a\n"
+       "configuration file:  the merged configuration depends on it (${ROOT},\n"
+       "${UUID}, ${LABEL} and ${FS_BYTES} interpolation, the local configuration\n"
+       "filename, and limits checked against the filesystem block size).\n"
+       "ROOT_PATH must be an existing directory that is the root of a mounted\n"
+       "btrfs filesystem, searchable by this user.\n";
+
+/// Report a --show-config ROOT_PATH problem and the requirement behind it.
 static
 void
-log_show_config_root_reason()
+show_config_root_fail(const string &what)
 {
-       for (const auto line : show_config_root_reason) {
-               BEESLOGERR(line);
-       }
+       cerr << "--show-config: " << what << "\n" << show_config_root_reason << flush;
 }
 
 /// Check the cheap, explainable requirements on a --show-config
 /// ROOT_PATH before opening it, so a wrong argument gets a message
 /// naming the requirement instead of a bare errno from deep inside
-/// context setup.  Returns false after logging if the path cannot
+/// context setup.  Returns false after reporting if the path cannot
 /// qualify.  Permission problems surface as stat/statfs errors, and
 /// only search permission is needed:  bees never reads the directory.
 static
@@ -180,24 +179,20 @@ check_show_config_root(const string &path)
 {
        struct stat st;
        if (stat(path.c_str(), &st)) {
-               BEESLOGERR("--show-config: cannot access '" << path << "': " << strerror(errno));
-               log_show_config_root_reason();
+               show_config_root_fail("cannot access '" + path + "': " + strerror(errno));
                return false;
        }
        if (!S_ISDIR(st.st_mode)) {
-               BEESLOGERR("--show-config: '" << path << "' is not a directory");
-               log_show_config_root_reason();
+               show_config_root_fail("'" + path + "' is not a directory");
                return false;
        }
        struct statfs sfs;
        if (statfs(path.c_str(), &sfs)) {
-               BEESLOGERR("--show-config: cannot statfs '" << path << "': " << strerror(errno));
-               log_show_config_root_reason();
+               show_config_root_fail("cannot statfs '" + path + "': " + strerror(errno));
                return false;
        }
        if (sfs.f_type != BTRFS_SUPER_MAGIC) {
-               BEESLOGERR("--show-config: '" << path << "' is not on a btrfs filesystem");
-               log_show_config_root_reason();
+               show_config_root_fail("'" + path + "' is not on a btrfs filesystem");
                return false;
        }
        return true;
@@ -481,8 +476,7 @@ bees_main(int argc, char *argv[])
                try {
                        bc->set_root_path(root_path);
                } catch (const exception &e) {
-                       BEESLOGERR("--show-config: '" << root_path << "' is not usable as ROOT_PATH: " << e.what());
-                       log_show_config_root_reason();
+                       show_config_root_fail("'" + root_path + "' is not usable as ROOT_PATH: " + e.what());
                        return EXIT_FAILURE;
                }
        } else {