]> granicus.if.org Git - jq/commitdiff
`error(x)` should not `tostring` its arg; fix #466
authorNicolas Williams <nico@cryptonector.com>
Tue, 8 Jul 2014 03:26:53 +0000 (22:26 -0500)
committerNicolas Williams <nico@cryptonector.com>
Tue, 8 Jul 2014 03:26:53 +0000 (22:26 -0500)
builtin.c
main.c

index 9089d47dd576a32573e483a95de416922b5acec9..69a413923c09a09b02f3a85eb026cb7681c4eebb 100644 (file)
--- a/builtin.c
+++ b/builtin.c
@@ -781,7 +781,6 @@ static jv f_type(jv input) {
 
 static jv f_error(jv input, jv msg) {
   jv_free(input);
-  msg = f_tostring(msg);
   return jv_invalid_with_msg(msg);
 }
 
diff --git a/main.c b/main.c
index 80497e779bc274af78a64675252548390e56b932..edf3f4fa3a70300673ee7882d4116aeb01ca0a23 100644 (file)
--- a/main.c
+++ b/main.c
@@ -127,7 +127,12 @@ static int process(jq_state *jq, jv value, int flags) {
   if (jv_invalid_has_msg(jv_copy(result))) {
     // Uncaught jq exception
     jv msg = jv_invalid_get_msg(jv_copy(result));
-    fprintf(stderr, "jq: error: %s\n", jv_string_value(msg));
+    if (jv_get_kind(msg) == JV_KIND_STRING) {
+      fprintf(stderr, "jq: error: %s\n", jv_string_value(msg));
+    } else {
+      msg = jv_dump_string(msg, 0);
+      fprintf(stderr, "jq: error (not a string): %s\n", jv_string_value(msg));
+    }
     jv_free(msg);
   }
   jv_free(result);