[SERVER-23135] js load() loses context on Syntax Errors Created: 14/Mar/16  Updated: 19/Nov/16  Resolved: 15/Sep/16

Status: Closed
Project: Core Server
Component/s: JavaScript
Affects Version/s: None
Fix Version/s: 3.3.14

Type: Improvement Priority: Minor - P4
Reporter: Eric Milkie Assignee: Matt Cotter
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Sprint: Platforms 2016-09-19
Participants:

 Description   

If you use load() in a js file to load another js file with syntax errors, the interpreter may sometimes not print the line where the syntax error is, due to the way we have implemented the load() function.

For example:

1.js

load("2.js");

2.js

// this is 2
// 
//
..................)

Running 2.js by itself works properly and gives the exact line and column of the error:

/data/m/ent/mongo: ./mongo 2.js --nodb
MongoDB shell version: 0.0.0
2016-03-14T17:07:27.632-0400 E QUERY    [thread1] SyntaxError: expected rest argument name, got '...' @2.js:4:3
 
failed to load: 2.js

Running 1.js loses context – no way to know where the error is:

/data/m/ent/mongo: ./mongo 1.js --nodb
MongoDB shell version: 0.0.0
2016-03-14T17:07:33.644-0400 E QUERY    [thread1] SyntaxError: expected rest argument name, got '...' :
@1.js:1:1
 
2016-03-14T17:07:33.644-0400 E QUERY    [thread1] Error: error loading js file: 2.js :
@1.js:1:1
 
failed to load: 1.js

I have noticed, however, that Reference Errors do not suffer from this, and always print the context even if they are nested within load().



 Comments   
Comment by Githook User [ 15/Sep/16 ]

Author:

{u'username': u'Machyne', u'name': u'Matt Cotter', u'email': u'matt.cotter@mongodb.com'}

Message: SERVER-23135 properly print context on js load

This patch ensures that we print the correct filename and line number
for syntax errors encountered in included js files via `load()`.
Branch: master
https://github.com/mongodb/mongo/commit/7b6cf36cb72558ed199f4ecde945ac3723229c3a

Comment by Eric Milkie [ 09/Sep/16 ]

Matt and I noticed that the command line spidermonkey client prints the file and line number for syntax errors (although their call stack is still missing frames just like ours!). So we are looking into doing the same thing for the mongo js shell.

Comment by Eric Milkie [ 09/Sep/16 ]

(Example is calling a function that isn't defined.)

Comment by Matt Cotter [ 09/Sep/16 ]

milkie - what did you mean by

I have noticed, however, that Reference Errors do not suffer from this, and always print the context even if they are nested within load().

Can you add an example?

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