Open Bug 1474287 Opened 6 years ago Updated 2 years ago

Full error messages not logged in the console (mach + xpcshell)

Categories

(Testing :: XPCShell Harness, defect, P3)

Version 3
x86_64
macOS
defect

Tracking

(Not tracked)

People

(Reporter: ladybenko, Unassigned)

Details

(Whiteboard: dev-prod-2020)

Attachments

(1 file)

When running xpcshell tests with mach, and there's a JS error in the code, instead of getting the actual error type and message, I'm getting a generic "ERROR NS_ERROR_NOT_AVAILABLE" plus the line and file, which makes debugging more difficult.
Can you provide a log showing the problem? Copy/paste the command line + the relevant output as a comment, or redirect output to a file and attach here, please.
Flags: needinfo?(balbeza)
There's a chance you can get what you need with existing command line arguments, like 'mach xpcshell-test --verbose ...' or possibly --log-mach-level=debug. See 'mach help xpcshell-test' or 'mach help test' for help on many options.
Flags: needinfo?(balbeza)
Hi, thanks! I've tried with both verbose and debug and I can't still get the error message. I'm attaching a patch to reproduce. Apply the patch, build Firefox and then run `./mach test devtools/client/application/test/unit/test_component.js`
I guess command line options won't help here after all.

I see:

...
 0:01.39 ERROR NS_ERROR_NOT_AVAILABLE: 
@/home/gbrown/objdirs/firefox/_tests/xpcshell/devtools/client/application/test/unit/test_component.js:5:17
load_file@/home/gbrown/src/testing/xpcshell/head.js:640:7
_load_files@/home/gbrown/src/testing/xpcshell/head.js:652:3
_execute_test@/home/gbrown/src/testing/xpcshell/head.js:506:3
@-e:1:1
...

That error message is formatted by

https://dxr.mozilla.org/mozilla-central/rev/085cdfb90903d4985f0de1dc7786522d9fb45596/testing/xpcshell/head.js#764


If I simply log the caught error instead, I get:

 0:00.45 ERROR [Exception... "Component is not available"  nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)"  location: "JS frame :: /home/gbrown/objdirs/firefox/_tests/xpcshell/devtools/client/application/test/unit/test_component.js :: <TOP_LEVEL> :: line 5"  data: no]


Is it the "0x80040111" and/or "Component is not available" text that you want to see?
Hi Geoff, thanks for looking into this. "Component is not available" is definitely something I'd like to see. In this case in particular, I actually thought that "NS_ERROR_NOT_AVAILABLE" meant that the error itself couldn't be retrieved (i.e. a tool error rather than a JavaScript error). Human-readable errors instead of (or in addition to) error codes would help a lot.
Looking at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error, it seems "name" and "message" are the only relevant standard properties. The xpcshell error logging already reports both. In this case, name = "NS_ERROR_NOT_AVAILABLE" and message = "".

I think "Component is not available" can only be accessed with toString(), which returns all that other text like "nsresult: ... location: ... data: ...".

I wouldn't want to dump the error's toString() text in addition to the existing stack:

ERROR NS_ERROR_NOT_AVAILABLE: 
@/home/gbrown/objdirs/firefox/_tests/xpcshell/devtools/client/application/test/unit/test_component.js:5:17
load_file@/home/gbrown/src/testing/xpcshell/head.js:640:7
_load_files@/home/gbrown/src/testing/xpcshell/head.js:652:3
_execute_test@/home/gbrown/src/testing/xpcshell/head.js:506:3
@-e:1:1
ERROR [Exception... "Component is not available"  nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)"  location: "JS frame :: /home/gbrown/objdirs/firefox/_tests/xpcshell/devtools/client/application/test/unit/test_component.js :: <TOP_LEVEL> :: line 5"  data: no]

I think the redundancy -- 2x "NS_ERROR_NOT_AVAILABLE", stack + location -- would be confusing. And I wouldn't want to remove the existing stack reporting, which is obviously more exact and more useful than the simple location returned by toString().

I would like to see text like "Component is not available" included when it is available, but I don't see a generic way to do that without losing some of the benefits of the existing error reporting.
Priority: -- → P3
It sounds more like an issue with ChromeUtils.import, called from test_component.js:5, that doesn't throw an error with meaningful error message, rather than an issue with xpcshell test harness.

Component is not available is the string to describe NS_ERROR_NOT_AVAILABLE:
  https://searchfox.org/mozilla-central/search?q=Component+is+not+available&case=false&regexp=false&path=
I'm not sure there is any API to fetch it from the exception, nor any api to translate a code into a message.

Also, I'm not sure if it is really helpful to retrieve the message, but you could do that via:
  const message = exception.__proto__ == Components.Exception().__proto__ ? exception.toString().match(/\"([^"]*)\"/)[1] : null;
Whiteboard: dev-prod-2020
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: