You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Pascal Bach (JIRA)" <ji...@apache.org> on 2011/07/06 09:32:16 UTC

[jira] [Created] (THRIFT-1232) JavaScript TException should be a constructor function

JavaScript TException should be a constructor function
------------------------------------------------------

                 Key: THRIFT-1232
                 URL: https://issues.apache.org/jira/browse/THRIFT-1232
             Project: Thrift
          Issue Type: Bug
          Components: JavaScript - Library
            Reporter: Pascal Bach
            Priority: Minor


The JavaScript TException is declared as an object with a prototype property assigned to it.
It should be declared as a constructor function with a prototype. Otherwise exceptions derived from TException using Thrift.inherits are not instances of TException.

Example:
function DerivedException() {};
Thrift.inherits(DerivedException, Thrift.TException);
var ex = new DerivedException();
ex instanceof Thrift.TException // => Error as TException is not a function

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (THRIFT-1232) JavaScript TException should be a constructor function

Posted by "Henrique Mendonca (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-1232?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13060658#comment-13060658 ] 

Henrique Mendonca commented on THRIFT-1232:
-------------------------------------------

actually... following THRIFT-724 and https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error , I think it shouldn't inherit TException at all...

Perhaps extend it from Error like MDN suggests?

DerivedException = function(args) {
  this.prototype = Error.prototype;
  this.name = 'DerivedException';
...
}

then you could even get rid of Thrift.inherits() and Thrift.TException on Thrift.js all together.



> JavaScript TException should be a constructor function
> ------------------------------------------------------
>
>                 Key: THRIFT-1232
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1232
>             Project: Thrift
>          Issue Type: Bug
>          Components: JavaScript - Library
>            Reporter: Pascal Bach
>            Priority: Minor
>              Labels: exception-handling, js
>
> The JavaScript TException is declared as an object with a prototype property assigned to it.
> It should be declared as a constructor function with a prototype. Otherwise exceptions derived from TException using Thrift.inherits are not instances of TException.
> Example:
> function DerivedException() {};
> Thrift.inherits(DerivedException, Thrift.TException);
> var ex = new DerivedException();
> ex instanceof Thrift.TException // => Error as TException is not a function

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (THRIFT-1232) JavaScript TException should be a constructor function

Posted by "Pascal Bach (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-1232?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13061077#comment-13061077 ] 

Pascal Bach commented on THRIFT-1232:
-------------------------------------

I agree it is probably best to make user defined exceptions inherit directly from JavaScripts Error.

But I belive the Mozilla example you show is wrong.

DerivedException = function(args) { this.name = 'DerivedException'; ... }
DerivedException.prototype = Error.prototype; 




> JavaScript TException should be a constructor function
> ------------------------------------------------------
>
>                 Key: THRIFT-1232
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1232
>             Project: Thrift
>          Issue Type: Bug
>          Components: JavaScript - Library
>            Reporter: Pascal Bach
>            Priority: Minor
>              Labels: exception-handling, js
>
> The JavaScript TException is declared as an object with a prototype property assigned to it.
> It should be declared as a constructor function with a prototype. Otherwise exceptions derived from TException using Thrift.inherits are not instances of TException.
> Example:
> function DerivedException() {};
> Thrift.inherits(DerivedException, Thrift.TException);
> var ex = new DerivedException();
> ex instanceof Thrift.TException // => Error as TException is not a function

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (THRIFT-1232) JavaScript TException should be a constructor function

Posted by "Pascal Bach (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/THRIFT-1232?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Pascal Bach updated THRIFT-1232:
--------------------------------

    Attachment: 0001-Improve-Exception-handling.patch

TException is now derived from JavaScripts Error.

Further the generated js exception code sets the name attribute to the name of the Struct. This allows javascript to display the by its real name instead of just Error.

DerivedException instanceof Error // => true
DerivedException instanceof TException // => true

Are now working

> JavaScript TException should be a constructor function
> ------------------------------------------------------
>
>                 Key: THRIFT-1232
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1232
>             Project: Thrift
>          Issue Type: Bug
>          Components: JavaScript - Library
>            Reporter: Pascal Bach
>            Priority: Minor
>              Labels: exception-handling, js
>         Attachments: 0001-Improve-Exception-handling.patch
>
>
> The JavaScript TException is declared as an object with a prototype property assigned to it.
> It should be declared as a constructor function with a prototype. Otherwise exceptions derived from TException using Thrift.inherits are not instances of TException.
> Example:
> function DerivedException() {};
> Thrift.inherits(DerivedException, Thrift.TException);
> var ex = new DerivedException();
> ex instanceof Thrift.TException // => Error as TException is not a function

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Resolved] (THRIFT-1232) JavaScript TException should be a constructor function

Posted by "Roger Meier (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/THRIFT-1232?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Roger Meier resolved THRIFT-1232.
---------------------------------

    Resolution: Fixed
      Assignee: Pascal Bach

committed, thanks!

> JavaScript TException should be a constructor function
> ------------------------------------------------------
>
>                 Key: THRIFT-1232
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1232
>             Project: Thrift
>          Issue Type: Bug
>          Components: JavaScript - Library
>            Reporter: Pascal Bach
>            Assignee: Pascal Bach
>            Priority: Minor
>              Labels: exception-handling, js
>         Attachments: 0001-Improve-Exception-handling.patch, 1232-Improve-Exception-handling-and-make-error-hierarchy.patch
>
>
> The JavaScript TException is declared as an object with a prototype property assigned to it.
> It should be declared as a constructor function with a prototype. Otherwise exceptions derived from TException using Thrift.inherits are not instances of TException.
> Example:
> function DerivedException() {};
> Thrift.inherits(DerivedException, Thrift.TException);
> var ex = new DerivedException();
> ex instanceof Thrift.TException // => Error as TException is not a function

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (THRIFT-1232) JavaScript TException should be a constructor function

Posted by "Pascal Bach (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/THRIFT-1232?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Pascal Bach updated THRIFT-1232:
--------------------------------

    Attachment: 1232-Improve-Exception-handling-and-make-error-hierarchy.patch

I improved the prototype hirarchy in Thrift.js so it is now closer to the C++ code. TApplicationException is now derived from TException. This should give a more consisten feeling

> JavaScript TException should be a constructor function
> ------------------------------------------------------
>
>                 Key: THRIFT-1232
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1232
>             Project: Thrift
>          Issue Type: Bug
>          Components: JavaScript - Library
>            Reporter: Pascal Bach
>            Priority: Minor
>              Labels: exception-handling, js
>         Attachments: 0001-Improve-Exception-handling.patch, 1232-Improve-Exception-handling-and-make-error-hierarchy.patch
>
>
> The JavaScript TException is declared as an object with a prototype property assigned to it.
> It should be declared as a constructor function with a prototype. Otherwise exceptions derived from TException using Thrift.inherits are not instances of TException.
> Example:
> function DerivedException() {};
> Thrift.inherits(DerivedException, Thrift.TException);
> var ex = new DerivedException();
> ex instanceof Thrift.TException // => Error as TException is not a function

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (THRIFT-1232) JavaScript TException should be a constructor function

Posted by "Henrique Mendonca (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-1232?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13060457#comment-13060457 ] 

Henrique Mendonca commented on THRIFT-1232:
-------------------------------------------

+1
the current TException "class" is indeed quite odd...
could you submit a patch?

thanks

> JavaScript TException should be a constructor function
> ------------------------------------------------------
>
>                 Key: THRIFT-1232
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1232
>             Project: Thrift
>          Issue Type: Bug
>          Components: JavaScript - Library
>            Reporter: Pascal Bach
>            Priority: Minor
>              Labels: exception-handling, js
>
> The JavaScript TException is declared as an object with a prototype property assigned to it.
> It should be declared as a constructor function with a prototype. Otherwise exceptions derived from TException using Thrift.inherits are not instances of TException.
> Example:
> function DerivedException() {};
> Thrift.inherits(DerivedException, Thrift.TException);
> var ex = new DerivedException();
> ex instanceof Thrift.TException // => Error as TException is not a function

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (THRIFT-1232) JavaScript TException should be a constructor function

Posted by "Hudson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-1232?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13061938#comment-13061938 ] 

Hudson commented on THRIFT-1232:
--------------------------------

Integrated in Thrift #186 (See [https://builds.apache.org/job/Thrift/186/])
    THRIFT-1232 JavaScript TException should be a constructor function
Patch: Pascal Bach
file: 1232-Improve-Exception-handling-and-make-error-hierarchy.patch

roger : http://svn.apache.org/viewvc/?view=rev&rev=1144292
Files : 
* /thrift/trunk/compiler/cpp/src/generate/t_js_generator.cc
* /thrift/trunk/lib/js/thrift.js


> JavaScript TException should be a constructor function
> ------------------------------------------------------
>
>                 Key: THRIFT-1232
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1232
>             Project: Thrift
>          Issue Type: Bug
>          Components: JavaScript - Library
>            Reporter: Pascal Bach
>            Assignee: Pascal Bach
>            Priority: Minor
>              Labels: exception-handling, js
>         Attachments: 0001-Improve-Exception-handling.patch, 1232-Improve-Exception-handling-and-make-error-hierarchy.patch
>
>
> The JavaScript TException is declared as an object with a prototype property assigned to it.
> It should be declared as a constructor function with a prototype. Otherwise exceptions derived from TException using Thrift.inherits are not instances of TException.
> Example:
> function DerivedException() {};
> Thrift.inherits(DerivedException, Thrift.TException);
> var ex = new DerivedException();
> ex instanceof Thrift.TException // => Error as TException is not a function

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira