[SERVER-7292] mongoimport misleading error message Created: 08/Oct/12  Updated: 11/Jul/16  Resolved: 04/Jul/14

Status: Closed
Project: Core Server
Component/s: Tools
Affects Version/s: 2.0.7, 2.2.0
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: Gianfranco Palumbo Assignee: Unassigned
Resolution: Done Votes: 1
Labels: mongoimport, neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Participants:

 Description   

Specially on Windows:

When specifying a file to import with --file with a space (without double quotes),

> mongoimport -d db -c coll --file D:\Parsely data\articles_split.json

mongoimport will *not* display:

Mon Oct  8 10:03:02 ERROR: file doesn't exist: filename.

But

ERROR: multiple occurrences
 
Import CSV, TSV or JSON data into MongoDB.
 
options:
...

This is misleading because it seems it refers to multiple document occurrences.

Same error occurs on Mac:

> mongoimport -d test -c test --file test space.json
ERROR: multiple occurrences



 Comments   
Comment by Gianfranco Palumbo [ 04/Jul/14 ]

$ mongoimport --version
 version 2.6.3
$ mongoimport -d test -c test --file test space.json
Error parsing command line:  Multiple occurrences of option "--file"
try 'mongoimport --help' for more information

Comment by Tad Marshall [ 09/Oct/12 ]

I wasn't actually trying to make a point, just describe what is happening and why this is the error message you see.

This is certainly fixable with the addition of some code. We have access to the same argc/argv parameters that we are passing to Boost::program_options and we could add parsing that was better tuned to detecting typos and unquoted file specs with spaces. We could probably allow multiple occurrences of options and then complain after program_options gives them to us, so that program_options will not throw an exception, and then we could make our error message better.

I agree that this is an unfriendly and unhelpful error message.

Comment by Gianfranco Palumbo [ 09/Oct/12 ]

I understand you point, but wouldn't it be better "multiple command line options occurrences" or something similar to help avoid the confusion?

Comment by Tad Marshall [ 08/Oct/12 ]

This exception is thrown by Boost::program_options because it sees two filenames specified: "D:\Parsely" and "data\articles_split.json". We display "ERROR: " followed by the text of the Boost::program_options::multiple_occurrences exception, which is "multiple occurrences", and then display the command line options help text. You get the same behavior if you provide two collection names or two database names.

Generated at Thu Feb 08 03:14:07 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.