[njs] Interactive shell: improved error handling.

Dmitry Volyntsev xeioex at nginx.com
Thu Jul 12 12:24:33 UTC 2018


details:   http://hg.nginx.org/njs/rev/0c131f169fe6
branches:  
changeset: 554:0c131f169fe6
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Thu Jul 12 15:24:18 2018 +0300
description:
Interactive shell: improved error handling.

Previously, compilation errors were not reported in file mode.

diffstat:

 njs/njs_shell.c |  15 ++++-----------
 1 files changed, 4 insertions(+), 11 deletions(-)

diffs (52 lines):

diff -r c1f9fe4022bc -r 0c131f169fe6 njs/njs_shell.c
--- a/njs/njs_shell.c	Tue Jul 03 15:48:04 2018 +0300
+++ b/njs/njs_shell.c	Thu Jul 12 15:24:18 2018 +0300
@@ -229,7 +229,6 @@ static nxt_int_t
 njs_interactive_shell(njs_opts_t *opts, njs_vm_opt_t *vm_options)
 {
     njs_vm_t   *vm;
-    nxt_int_t  ret;
     nxt_str_t  line, out;
 
     vm = njs_vm_create(vm_options);
@@ -266,11 +265,7 @@ njs_interactive_shell(njs_opts_t *opts, 
 
         add_history((char *) line.start);
 
-        ret = njs_process_script(vm, opts, &line, &out);
-        if (ret != NXT_OK) {
-            printf("shell: failed to get retval from VM\n");
-            continue;
-        }
+        njs_process_script(vm, opts, &line, &out);
 
         printf("%.*s\n", (int) out.length, out.start);
 
@@ -385,7 +380,7 @@ njs_process_file(njs_opts_t *opts, njs_v
 
     ret = njs_process_script(vm, opts, &script, &out);
     if (ret != NXT_OK) {
-        fprintf(stderr, "failed to get retval from VM\n");
+        fprintf(stderr, "%.*s\n", (int) out.length, out.start);
         ret = NXT_ERROR;
         goto done;
     }
@@ -426,16 +421,14 @@ njs_process_script(njs_vm_t *vm, njs_opt
         }
 
         ret = njs_vm_run(vm);
-        if (ret == NXT_AGAIN) {
-            return ret;
-        }
     }
 
     if (njs_vm_retval_to_ext_string(vm, out) != NXT_OK) {
+        *out = nxt_string_value("failed to get retval from VM");
         return NXT_ERROR;
     }
 
-    return NXT_OK;
+    return ret;
 }
 
 


More information about the nginx-devel mailing list