[SERVER-32207] shell does not report a duplicate key error when creating a unique index fails Created: 07/Dec/17 Updated: 08/Jan/24 Resolved: 17/Aug/18 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Shell |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Derek Scherger | Assignee: | Mira Carey |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Operating System: | ALL | |||||||||||||||||||||||||||||||||||||||
| Steps To Reproduce: |
|
|||||||||||||||||||||||||||||||||||||||
| Participants: |
| Description |
|
running a scripted set of commands from the shell with `mongo tmp/foo.js` does not report errors |
| Comments |
| Comment by Mira Carey [ 17/Aug/18 ] | ||
|
Unfortunately the shell doesn't offer anything like bash "set -e" and we're not in a great position to plumb one at this point. The shell's error return as a process is largely related to errors in it's own processing, returning non-zero for errors in connect or for syntax errors. For errors from mongod, its not obvious when to turn those into top level errors. A user running a variety of commands may or may not expect any particular command result to succeed with any particular code. Executing an insert and seeing a duplicate key error can be perfectly valid, for instance. If you'd like to verify that any particular statement succeeded, you may assert that any particular statement succeeded with commands like:
or
| ||
| Comment by Derek Scherger [ 09/Dec/17 ] | ||
|
What I'm looking for is a generic, reliable way to determine whether an arbitrary script encountered errors or not. You are correct in that I can change the script to use `printjson(db.foo.createIndex( { foo: 1 }, { unique: true }));` which does display the error in a human readable way but if the script is running in a non-interactive environment that doesn't really help all that much. Additionally I would need to change every | ||
| Comment by Mark Agarunov [ 08/Dec/17 ] | ||
|
Hello derek@echologic.com, Thank you for the report. When using the mongo shell with a script, output can be returned by using print() or printjson(). This includes errors that are returned from mongod. Thanks, |