]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Improve error message for bad boolean environment variable value
authorJoel Rosdahl <joel@rosdahl.net>
Wed, 15 Jan 2020 20:53:58 +0000 (21:53 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Wed, 15 Jan 2020 20:53:58 +0000 (21:53 +0100)
Before:

    ccache: error: CCACHE_DIRECT: invalid boolean environment variable
    value "0" for CCACHE_NODIRECT (did you mean to set
    "CCACHE_DIRECT=true"?)

After:

    ccache: error: CCACHE_NODIRECT: invalid boolean environment variable
    value "0" (did you mean to set "CCACHE_DIRECT=true"?)

src/Config.cpp

index fd52e986ceaa0c97f22f3e3b10ea81e963c42782..a027ef94d1cdadf0dccc3a9dc7471e5b4d057313 100644 (file)
@@ -170,11 +170,9 @@ parse_bool(const std::string& value,
     if (value == "0" || lower_value == "false" || lower_value == "disable"
         || lower_value == "no") {
       throw Error(
-        fmt::format("invalid boolean environment variable value \"{}\" for"
-                    " CCACHE_{}{} (did you mean to set \"CCACHE_{}{}=true\"?)",
+        fmt::format("invalid boolean environment variable value \"{}\" (did"
+                    " you mean to set \"CCACHE_{}{}=true\"?)",
                     value,
-                    negate ? "NO" : "",
-                    *env_var_key,
                     negate ? "" : "NO",
                     *env_var_key));
     }
@@ -470,7 +468,8 @@ Config::update_from_environment()
     try {
       set_item(config_key, value, key, negate, "environment");
     } catch (const Error& e) {
-      throw Error(fmt::format("CCACHE_{}: {}", key, e.what()));
+      throw Error(
+        fmt::format("CCACHE_{}{}: {}", negate ? "NO" : "", key, e.what()));
     }
   }
 }