core
core copied to clipboard
processor CLI parser: improve error message for --parameter
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.)
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)
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.