Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Replace <Unknown Source> with Script file name

35 views
Skip to first unread message

Lord.Quackstar

unread,
May 1, 2010, 8:44:08 PM5/1/10
to dev-tech-js-...@lists.mozilla.org
Hello everyone,


In my code, all of the scripts are contained in .js files. Whenever one of the scripts contains an error, I get this:

javax.script.ScriptException: sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: "nonexistant" is not defined. (<Unknown source>#5) in <Unknown source> at line number 5

What bugs me is the <Unknown Source>. Multiple files are in one ScriptContext, and it can be hard to track down an error. It also looks horrible.

Is there a way to replace <Unknown Source> with the actual file name? None of the methods I see support passing a File object, so I'm really confused here.

Thanks,
Leon


Dan Howard

unread,
May 24, 2010, 8:10:31 AM5/24/10
to
Yeah. It's because you get your scripts from a url resource. That's
what I do too.

In my catch I do a replace:


String scriptSource = "save your source file name";

try {

script.eval(bindings);
} catch (ScriptException e) {
// We need to LOG and THROW. Log ensures that we get a CAUSED BY to
see where exactly
// an error could occur. Otherwise we'll only know where in the
script the problem is
// not where in the java code.
log.error(e.getMessage(), e);

// Since we pass a reader the exception will not have the source
// file name. We'll do a String replace to put it in there.
String msg = e.getMessage();
msg = StringUtil.replace(msg, "<Unknown Source>", scriptSource);

throw new ScriptException(msg);

0 new messages