exports.app = function(env) {
throw new Error("an error occurred");
return {
status : 200,
headers : {"Content-Type":"text/plain"},
body : ["test"]
};
};
How can I get the line number and file name of the exception? It's
especially critical for nested files and modules.
Currently it just prints:
Error: an error occurred
and the fileName and lineNumber properties of the exception object
(inside ShowExceptions middleware) are null.
RhinoExceptions would have a stack trace, but what about exceptions in
my own js?
Where is the Rhino config that comes bundled w/ narwhal?
Thanks a lot.
sk
Rhino by default follows the ES spec maybe to closely, which says
"Error instances have no special properties beyond those inherited
from the Error prototype object". To get fileName and lineNumber
properties in error objects without passing them to the constructor,
you have to set the Context.FEATURE_LOCATION_INFORMATION_IN_ERROR
property when you enter a Rhino context.
With a recent Rhino snapshot this also gives you a "stack" property
containing the JavaScript stack trace like the one on the bottom of
this page:
http://ringojs.org/demo/logging?error=1
Hannes
> --
> You received this message because you are subscribed to the Google Groups "Narwhal and Jack" group.
> To post to this group, send email to narw...@googlegroups.com.
> To unsubscribe from this group, send email to narwhaljs+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/narwhaljs?hl=en.
>
>
Does anybody know where this config gets loaded from jack?
I realize I can probably set it in init code as a hack, but it would
be nice not to.
Thanks.
On May 26, 1:01 am, Hannes Wallnoefer <han...@helma.at> wrote:
> 2010/5/26 sk <doyouunderst...@gmail.com>:
>
>
>
>
>
> > Given:
>
> > exports.app = function(env) {
> > throw new Error("an error occurred");
> > return {
> > status : 200,
> > headers : {"Content-Type":"text/plain"},
> > body : ["test"]
> > };
> > };
>
> > How can I get the line number and file name of the exception? It's
> > especially critical for nested files and modules.
>
> > Currently it just prints:
>
> > Error: an error occurred
>
> > and the fileName and lineNumber properties of the exception object
> > (inside ShowExceptions middleware) are null.
>
> > RhinoExceptions would have a stack trace, but what about exceptions in
> > my own js?
>
> Rhino by default follows the ES spec maybe to closely, which says
> "Error instances have no special properties beyond those inherited
> from the Error prototype object". To get fileName and lineNumber
> properties in error objects without passing them to the constructor,
> you have to set the Context.FEATURE_LOCATION_INFORMATION_IN_ERROR
> property when you enter a Rhino context.
>
> http://www.mozilla.org/rhino/apidocs/org/mozilla/javascript/Context.h...
I notice a narwhal.conf file as well which is the reason I ask.
Scott.
local narwhal.conf files and the engines/rhino/bootstrap.js don't seem
to be used in windows machines, so I'm not sure how to change rhino's
behavior.
What's worse is that the virtual environments feature isn't really
working properly on windows either. ie, require calls don't get
picked up for local lib/script files. One has to place them into jack/
lib to see them.
Can you provide example code of how you set the
Context.FEATURE_LOCATION_INFORMATION_IN_ERROR in code?
I see in Ringo you've overridden Context factory, but I'm hoping that
in narwhal's bootstrap.js file somehow I can just tell the current
context to turn this feature on? Since it's a static final though I'm
assuming it's getting it from config somewhere, but I can't see where
narwhal is providing this info.
Thanks.
Scott.
On May 26, 1:01 am, Hannes Wallnoefer <han...@helma.at> wrote:
> 2010/5/26 sk <doyouunderst...@gmail.com>:
>
>
>
>
>
> > Given:
>
> > exports.app = function(env) {
> > throw new Error("an error occurred");
> > return {
> > status : 200,
> > headers : {"Content-Type":"text/plain"},
> > body : ["test"]
> > };
> > };
>
> > How can I get the line number and file name of the exception? It's
> > especially critical for nested files and modules.
>
> > Currently it just prints:
>
> > Error: an error occurred
>
> > and the fileName and lineNumber properties of the exception object
> > (inside ShowExceptions middleware) are null.
>
> > RhinoExceptions would have a stack trace, but what about exceptions in
> > my own js?
>
> Rhino by default follows the ES spec maybe to closely, which says
> "Error instances have no special properties beyond those inherited
> from the Error prototype object". To get fileName and lineNumber
> properties in error objects without passing them to the constructor,
> you have to set the Context.FEATURE_LOCATION_INFORMATION_IN_ERROR
> property when you enter a Rhino context.
>
> http://www.mozilla.org/rhino/apidocs/org/mozilla/javascript/Context.h...
If you can get all errors to have backtraces by modifying
bootstrap.js, we'd be happy to merge it, for sure. I haven't had any
problem with that on other platforms, though, so I'm curious why it's
not working on Windows. Apart from that, it would be awesome if
someone could get the Windows bootstrapping to be an exact port of the
Unix bootstrapping. It's been 15 years since I wrote a batch file in
earnest.
Kris Kowal
--
You received this message because you are subscribed to the Google Groups "Narwhal and Jack" group.
To post to this group, send email to narw...@googlegroups.com.
To unsubscribe from this group, send email to narwhaljs+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/narwhaljs?hl=en.
Looking at the code, I'm afraid the only way to activate this feature
is to subclass either Rhino's Context or ContextFactory class,
overriding the hasFeature() method. You can do a lot from JS in Rhino,
but the Context/ContextFactory code runs before you enter any JS, so
you have to write some Java eventually.
Hannes
I tried overridding both Context and ContextFactory in bootstrap.js in
order to provide my own implementation of hasFeature, but neither
worked. No stack traces in either instance, even though
Context.FEATURE_LOCATION_INFORMATION_IN_ERROR was set to true.
I just can't believe that mozilla doesn't have a config property for
this.
I'm at a loss at this point, and without stack traces don't think I
can build anything using Jack on windows. Maybe after some sleep
something will come to me.
Scott.
I have stack traces too now. :) There was a bug w/ my java factory
implementation, which meant that my overridden hasFeature wasn't being
called at the right time.
So, I have stack traces for all the built in javascript errors
(syntax, type, etc), but for custom exceptions (such as the example I
started this thread with, ie: throw new Error("crash!"), there is no
trace. This is much less critical as developers can usually be
expected to provide some context manually, but I wonder if there's yet
another bug I'm missing, or if currently any exceptions thrown by your
own code are not going to be traced through Rhino?
Thanks again for all the help you guys.
sk
On May 26, 6:31 pm, Dean Landolt <d...@deanlandolt.com> wrote:
> > narwhaljs+...@googlegroups.com<narwhaljs%2Bunsubscribe@googlegroups .com>
> > .
> > > >> > For more options, visit this group athttp://
> > groups.google.com/group/narwhaljs?hl=en.
>
> > > > --
> > > > You received this message because you are subscribed to the Google
> > Groups "Narwhal and Jack" group.
> > > > To post to this group, send email to narw...@googlegroups.com.
> > > > To unsubscribe from this group, send email to
> > narwhaljs+...@googlegroups.com<narwhaljs%2Bunsubscribe@googlegroups .com>
> > .
> > > > For more options, visit this group athttp://
> > groups.google.com/group/narwhaljs?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Narwhal and Jack" group.
> > To post to this group, send email to narw...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > narwhaljs+...@googlegroups.com<narwhaljs%2Bunsubscribe@googlegroups .com>
Wait - for syntax and type errors and exceptions thrown in Java you
should have had location information and stack traces all along. The
feature we talked about _only_ affects errors created via new Error()
constructor.
So if you don't get file names and line numbers for new Error(), your
ContextFactory is still not doing anything, which is what I'd expect
if you set it from JavaScript (i.e. when a context has already been
created and entered). That's just a chicken/egg problem with the way
narwhal's rhino bootstrap mechanism works.
Hannes
> To unsubscribe from this group, send email to narwhaljs+...@googlegroups.com.