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

Throw objects not strings

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor - P4
    • Resolution: Duplicate
    • None
    • None
    • Internal Code, JavaScript, Shell
    • Minor Change

    Description

      Currently we throw with strings in js code (collection/db/query/mongo/etc) when we have an object/bsonobj. We should simply build a wrapper object and throw that.

      $ grep -i throw.*tojson\( src/mongo/shell/*.js
      src/mongo/shell/collection.js:        throw "error " + tojson( ret );
      src/mongo/shell/collection.js:    throw "error dropping indexes : " + tojson( res );
      src/mongo/shell/collection.js:        throw "drop failed: " + tojson( ret );
      src/mongo/shell/collection.js:        throw "findAndModifyFailed failed: " + tojson( ret );
      src/mongo/shell/collection.js:        throw "distinct failed: " + tojson( res );
      src/mongo/shell/collection.js:        throw "distinct failed: " + tojson( res );
      src/mongo/shell/collection.js:        throw "aggregate failed: " + tojson(res);
      src/mongo/shell/collection.js:        throw "map reduce failed:" + tojson(raw);
      src/mongo/shell/db.js:            throw "Could not insert into system.users: " + tojson(e);
      src/mongo/shell/db.js:        throw "profile command failed: " + tojson( res );
      src/mongo/shell/db.js:          throw tojson( res );
      src/mongo/shell/db.js:        throw "group command failed: " + tojson( ret );
      src/mongo/shell/db.js:        throw "getlasterror failed: " + tojson( res );
      src/mongo/shell/db.js:        throw "getlasterror failed: " + tojson( res );
      src/mongo/shell/mongo.js:        throw "listDatabases failed:" + tojson( res );
      src/mongo/shell/query.js:        throw "error: " + tojson( ret );
      src/mongo/shell/query.js:        throw "error: " + tojson( ret );
      src/mongo/shell/query.js:    throw "count failed: " + tojson( res );
      src/mongo/shell/query.js:            throw "error: " + tojson( ret );
      src/mongo/shell/shardingtest.js:    throw "command " + tojson( cmd ) + " failed: " + tojson( res );

      In addition to these we should fix all "throw <string>" instances to throw "Error(<string>)".

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              scotthernandez Scott Hernandez
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: