[SERVER-28136] doassert() should ensure its Error object's message is one line Created: 27/Feb/17  Updated: 27/Oct/23  Resolved: 02/Mar/17

Status: Closed
Project: Core Server
Component/s: JavaScript, Shell, Testing Infrastructure
Affects Version/s: 3.5.3
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Robert Guo (Inactive) Assignee: Robert Guo (Inactive)
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Backwards Compatibility: Fully Compatible
Sprint: TIG 2017-03-06
Participants:

 Description   

When an exception is thrown, the shell would print it in the following format:

2017-02-16T23:02:31.486+0000 E QUERY    [thread1] Error: [some error message]

The error message can span multiple lines, making parsing them difficult. 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.



 Comments   
Comment by Robert Guo (Inactive) [ 28/Feb/17 ]

Closing this as "works as designed". Even though server logs are all single-line. Shell error messages can span multiple lines for readability.

The automated parsing code has been changed to traverse backwards from the "failed to load" message instead of searching the for "E QUERY" line.

Comment by Max Hirschhorn [ 28/Feb/17 ]

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:

  1. 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.
  2. 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.

Generated at Thu Feb 08 04:17:13 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.