Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-23135

js load() loses context on Syntax Errors

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Done
    • Icon: Minor - P4 Minor - P4
    • 3.3.14
    • None
    • JavaScript
    • None
    • Fully Compatible
    • Platforms 2016-09-19

    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().

      Attachments

        Activity

          People

            matt.cotter Matt Cotter
            milkie@mongodb.com Eric Milkie
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: