]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
In typed_var_kvassign, include config names in error messages.
authorNick Mathewson <nickm@torproject.org>
Wed, 26 Feb 2020 19:16:55 +0000 (14:16 -0500)
committerNick Mathewson <nickm@torproject.org>
Wed, 26 Feb 2020 19:18:40 +0000 (14:18 -0500)
This should improve the usability of our configuration error messages.

src/lib/confmgt/typedvar.c
src/test/test_options.c

index 3a188db953f838b4780e21c6d520d434a12759fb..1955302cdc6470d0f6e0ff11a08ab2be11d4bf02 100644 (file)
@@ -24,6 +24,7 @@
 #include "lib/log/log.h"
 #include "lib/log/util_bug.h"
 #include "lib/malloc/malloc.h"
+#include "lib/string/printf.h"
 #include "lib/string/util_string.h"
 
 #include "lib/confmgt/var_type_def_st.h"
@@ -75,7 +76,15 @@ typed_var_kvassign(void *target, const config_line_t *line,
     return def->fns->kv_parse(target, line, errmsg, def->params);
   }
 
-  return typed_var_assign(target, line->value, errmsg, def);
+  int rv = typed_var_assign(target, line->value, errmsg, def);
+  if (rv < 0 && *errmsg != NULL) {
+    /* typed_var_assign() didn't know the line's keyword, but we do.
+     * Let's add it to the error message. */
+    char *oldmsg = *errmsg;
+    tor_asprintf(errmsg, "Could not parse %s: %s", line->key, oldmsg);
+    tor_free(oldmsg);
+  }
+  return rv;
 }
 
 /**
index 129a8299e342c70b19253519d85a2d2ce2433aff..636d3c0e54413c69ae5822cafdc88e43ace45360 100644 (file)
@@ -4269,7 +4269,8 @@ test_options_trial_assign(void *arg)
   v = options_trial_assign(lines, 0, &msg);
   tt_int_op(v, OP_EQ, SETOPT_ERR_PARSE);
   tt_str_op(msg, OP_EQ,
-            "Unrecognized value ambidextrous. Allowed values are 0 and 1.");
+            "Could not parse UseBridges: Unrecognized value ambidextrous. "
+            "Allowed values are 0 and 1.");
   tor_free(msg);
   config_free_lines(lines);