core icon indicating copy to clipboard operation
core copied to clipboard

processor CLI parser: improve error message for --parameter

Open bertsky opened this issue 3 years ago • 2 comments

The ambiguity of --parameter (JSON string or filename) currently makes the behaviour very confusing if you pass a filename that does not exist (but is clearly not a JSON string either):

... parse_json_string_or_file
    raise err       # pylint: disable=raising-bad-type
ValueError: Error parsing 'presets_TableBank_X152.json': Expecting value: line 1 column 1 (char 0)

Instead, this should be something like a FileNotFoundError.

(The example is from https://github.com/OCR-D/core/issues/930, but this problem is more general.)

bertsky avatar Oct 27 '22 23:10 bertsky

How about changing https://github.com/OCR-D/core/blob/f0e02361f31e7542bcea9a05e316ea161408cdd0/ocrd_utils/ocrd_utils/str.py#L177 into

    err = ValueError("Not a valid JSON file or string: '%s'" % value)

bertsky avatar Nov 04 '22 07:11 bertsky

I've been bitten by this too. How about:

a. Changing the error message as @bertsky proposed

and also

b. introducing another CLI option --parameter-file that only takes a file, while deprecating using --parameter with a file? This would remove the ambiguity. I think this could at least be discussed.

mikegerber avatar Feb 24 '23 16:02 mikegerber