It would be nice if doassert() could remove the newlines in the Error object before throwing it but after printing the message explicitly. This way there will still be a human readable multiline version of the message.
robert.guo, as I understand it, this ticket is about changing the mongo shell's behavior to makie it easier for the tool you're working on to parse JavaScript exceptions. I'd like to better understand why parsing multi-line error messages from the mongo shell is difficult and/or cannot be made reliable.
With your current proposal, I'd like to point out the following things:
- There are other places in the mongo shell where an Error object is thrown in JS tests aside from doassert(), so this approach won't solve the general case.
- I'd like to eventually remove the print(ex.stack) line in doassert() as it leads to misleading JavaScript backtraces when using assert.throws().
If there's difficulty in knowing when the JavaScript assertion message ends, would having a "BEGIN BACKTRACE"- and "END BACKTRACE"-like message help demarcate what lines of output are part of the assertion message? What strategy do you have planned for parsing MongoDB backtraces?
If you'd like to modify the log output for all uncaught JavaScript exceptions, then you should take a look at MozJSImplScope::_reportError(). Note that we'd need to get additional buy-in from the Platforms team for anything you'd propose to do there.
|