Uploaded image for project: 'MongoDB Shell'
  1. MongoDB Shell
  2. MONGOSH-739

Throwing primitives leads to confusing output

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 0.13.1
    • Affects Version/s: None
    • Component/s: CLI Module
    • 2
    • Iteration Barcelona
    • Not Needed

      Enterprise replset [direct: primary]> throw 1
      Uncaught 
      Enterprise replset [direct: primary]> throw null
      Enterprise replset [direct: primary]> 
      Enterprise replset [direct: primary]> throw {}
      Uncaught 
      Enterprise replset [direct: primary]> throw { printable: 1 }
      Uncaught 1
      

      The first & third one are happening because the MongoshNodeRepl.writer function expects either an Error or a ShellResult, but when it receives a primitive or generally an object that is neither which lacks the ShellResult properties, it ends up being treated like undefined.

      The second one is because passing null back to the REPL eval’s callback function as an Error makes it seem like no error occurred.

      The best solution is probably to wrap non-Error error values in Errors once evaluation finishes.

            Assignee:
            anna.henningsen@mongodb.com Anna Henningsen
            Reporter:
            anna.henningsen@mongodb.com Anna Henningsen
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: