Closed Bug 286450 Opened 19 years ago Closed 19 years ago

nsScriptError.message is not very helpful

Categories

(Core :: XPConnect, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla1.8beta2

People

(Reporter: benjamin, Assigned: benjamin)

Details

Attachments

(1 file, 1 obsolete file)

nsScriptError implements nsIConsoleMessage.message as the plain error message
without line# etc. Instead, nsIConsoleMessage.message should return the same
thing as nsIScriptError.toString, and there should be a separate attribute on
nsIScriptError to access the "bare" error message. Patch coming up.

I need this for error logging to file in xulrunner/toolkit startup.
Attached patch Add nsIScriptError.errorMessage (obsolete) — Splinter Review
Attachment #177633 - Flags: superreview?(bzbarsky)
Attachment #177633 - Flags: review?(dbradley)
Don't forget to change the interface UUID!
Comment on attachment 177633 [details] [diff] [review]
Add nsIScriptError.errorMessage

you should check for OOM from ToNewUnicode before returning NS_OK; but why add
a method that's redundant with toString?
Yeah, what biesi said.. having two methods/properties that do the same exact
thing seems a little odd.  Why not just use toString() in whatever code it is
you have?
Because my logging code is XPCOM-only (it does not and cannot know about
nsIScriptError). Basically, this makes the nsIConsoleMessage interface output a
reasonably helpful error message even without knowing anything about nsIScriptError.
Comment on attachment 177633 [details] [diff] [review]
Add nsIScriptError.errorMessage

Ah, I see.

>Index: js/src/xpconnect/idl/nsIScriptError.idl

Like darin said, rev the uuid.

>+    /**
>+     * The error message without any context/line number information.
>+     */
>+    readonly attribute wstring errorMessage;

Probably worth more clearly documenting how this differs from the "message"
attribute...

Also, possibly worth making this an AString, not a wstring.

>Index: js/src/xpconnect/src/nsScriptError.cpp

>+    nsXPIDLCString message;
>+    rv = ToString(getter_Copies(message));

So now "message" is in what encoding?  Looking at ToString(), it's just taking
the UTf-16 string and dropping the high bytes...

>+    *result = ToNewUnicode(message);

And then we byte-expand.  So ISO-8859-1 will survive this procedure, but
everything else is screwed.

I'd sort of prefer something that didn't do that (perhaps use ToNewUTF8String
in toString() and then UTFtoNewUnicode, or CopyUTF8ToUTF16 depending on what
the attr ends up returning here?).
Attachment #177633 - Flags: superreview?(bzbarsky) → superreview-
Attachment #177633 - Attachment is obsolete: true
Attachment #177865 - Flags: superreview?(bzbarsky)
Attachment #177865 - Flags: review?(dbradley)
Comment on attachment 177865 [details] [diff] [review]
Add nsIScriptError.errorMessage and use new string types

Much happier!  sr=bzbarsky.
Attachment #177865 - Flags: superreview?(bzbarsky) → superreview+
Comment on attachment 177865 [details] [diff] [review]
Add nsIScriptError.errorMessage and use new string types

r=dbradley
Attachment #177865 - Flags: review?(dbradley) → review+
Fixed on trunk.
Status: NEW → RESOLVED
Closed: 19 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla1.8beta2
js/src/xpconnect/src/xpcconvert.cpp
+        data->ToString(formattedMsg);
 
         rv = ConstructException(NS_ERROR_XPC_JAVASCRIPT_ERROR_WITH_DETAILS,
-                                formattedMsg, ifaceName, methodName, data,
+                                formattedMsg.get(), ifaceName, methodName, data,

Does this use the correct charset?
Comment on attachment 177633 [details] [diff] [review]
Add nsIScriptError.errorMessage

patch is obsolete, removing review request
Attachment #177633 - Flags: review?(dbradley)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: