[ 
https://issues.apache.org/jira/browse/THRIFT-3916?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16565571#comment-16565571
 ] 

ASF GitHub Bot commented on THRIFT-3916:
----------------------------------------

jeking3 closed pull request #1075: THRIFT-3916 Throw proper errors from JS, not 
strings
URL: https://github.com/apache/thrift/pull/1075
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/compiler/cpp/src/generate/t_js_generator.cc 
b/compiler/cpp/src/generate/t_js_generator.cc
index af0f28426e..209bcaf00e 100644
--- a/compiler/cpp/src/generate/t_js_generator.cc
+++ b/compiler/cpp/src/generate/t_js_generator.cc
@@ -66,7 +66,7 @@ class t_js_generator : public t_oop_generator {
       } else if( iter->first.compare("ts") == 0) {
         gen_ts_ = true;
       } else {
-        throw "unknown option js:" + iter->first; 
+        throw "unknown option js:" + iter->first;
       }
     }
 
@@ -1565,10 +1565,11 @@ void t_js_generator::generate_service_client(t_service* 
tservice) {
 }
 
 std::string t_js_generator::render_recv_throw(std::string var) {
+  std::string error = "new Error(" + var + ")";
   if (gen_node_) {
-    return "return callback(" + var + ");";
+    return "return callback(" + error + ");";
   } else {
-    return "throw " + var + ";";
+    return "throw " + error + ";";
   }
 }
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Errors thrown from JavaScript client is strings and not errors
> --------------------------------------------------------------
>
>                 Key: THRIFT-3916
>                 URL: https://issues.apache.org/jira/browse/THRIFT-3916
>             Project: Thrift
>          Issue Type: Bug
>          Components: JavaScript - Compiler
>            Reporter: Simen Bekkhus
>            Priority: Minor
>              Labels: javascript
>
> In JavaScript, you can {{throw}} any object, including strings, but to get 
> stack traces one should throw {{Errors}}.
> The generated JS code throws the error string directly, instead of wrapping 
> it in {{new Error}}.
> Node core _only_ rejects with/throws Errors, never strings, and Thrift should 
> follow the same standard.
> https://nodejs.org/api/errors.html#errors_class_error
> {quote}
> All errors generated by Node.js, including all System and JavaScript errors, 
> will either be instances of, or inherit from, the Error class.
> {quote}
> PR for the change [here|https://github.com/apache/thrift/pull/1075].



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to