Closed Bug 317476 Opened 19 years ago Closed 19 years ago

The error thrown by JS_ReportError is not catchable

Categories

(Core :: JavaScript Engine, defect, P3)

defect

Tracking

()

VERIFIED FIXED
mozilla1.9alpha1

People

(Reporter: mrbkap, Assigned: mrbkap)

References

Details

(Keywords: verified1.8.1, Whiteboard: [have patch])

Attachments

(2 files, 1 obsolete file)

This was brought up by bug 304033. When you call JS_ReportError, the error corresponds to JSMSG_NOT_AN_ERROR, so given the shell function:

static JSBool
ThrowError(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
    JS_ReportError(cx, "This is an error");
    return JS_FALSE;
}

And calling it as throwError:
js> try { throwError(); } catch(e) { E = e }
typein:1: This is an error
js> E
typein:2: ReferenceError: E is not defined

I have a patch to fix this.
Status: NEW → ASSIGNED
Priority: -- → P3
Attached patch Make it catchable (obsolete) — Splinter Review
I don't know if we want the js.c changes. I didn't feel like chasing down uses of JS_ReportError in js.c to test this, but ThrowError is pretty trivial.
Attachment #203982 - Flags: review?(brendan)
Blocks: 304033
Whiteboard: [have patch]
So what message do you get for an uncaught user-defined error report?  The useless one in js.msg, or the one the user passed to JS_ReportError?

/be
At least in the JS shell, I get the message passed into JS_ReportError (the expected one), I'm pretty sure I also saw the right behavior when I tested earlier, but I can't test now.
The old patch showed:
"Error: Error: message"

In the JS console because the report didn't offer a ucmessage so we were using the result of exception.toString() which duplicated the "Error". This patch gives a ucmessage so that clients that just want the wide message can get it.
Attachment #203982 - Attachment is obsolete: true
Attachment #204055 - Flags: review?(brendan)
Attachment #203982 - Flags: review?(brendan)
Please imagine that I JS_free the inflated string.
Comment on attachment 204055 [details] [diff] [review]
Fixing the report in the JS console

Why not JSMSG_USER_DEFINED_ERROR?

I'm imagining that inflated string being JS_free'd, but a new patch would be cool.  Too bad we can't suppress the OOM that will nest in any js_ReportErrorVA call that hits a hard limit under js_InflateString.

/be
Attachment #204055 - Flags: review?(brendan) → review+
This also nukes a warning about report.ucmessage being a |const jschar *|.

I think the USERDEFINED (no _) came from the htmlparser eHTMLTag_userdefined that I seem to be so used to.
Attachment #204336 - Flags: review?(brendan)
Comment on attachment 204336 [details] [diff] [review]
with comments addressed

Rename the "last" local in js_ReportErrorVA to "message" (the name "last" is ancient, and had to do with keeping the last error message owned by the cx on which it was reported), if you can. r=me on that if it's a followup patch.

/be
Attachment #204336 - Flags: review?(brendan) → review+
Fix checked in, with the additional s/last/message/ renaming.
Status: ASSIGNED → RESOLVED
Closed: 19 years ago
Resolution: --- → FIXED
Checking in regress-317476.js;
/cvsroot/mozilla/js/tests/js1_5/Regress/regress-317476.js,v  <--  regress-317476.js
initial revision: 1.1
done
Status: RESOLVED → VERIFIED
Flags: testcase+
fixed by Bug 336373 on the 1.8.1 branch. 
verified fixed 1.8.1 with windows/macppc/linux 20060707
Keywords: verified1.8.1
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: