Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interpreter.tryConvert should set cause exception #1128

Closed
remkop opened this issue Jul 16, 2020 · 0 comments
Closed

Interpreter.tryConvert should set cause exception #1128

remkop opened this issue Jul 16, 2020 · 0 comments

Comments

@remkop
Copy link
Owner

remkop commented Jul 16, 2020

Interpreter.tryConvert should set cause exception, so that stack trace shows the cause (which may be a custom converter).

Should be:

        private Object tryConvert(ArgSpec argSpec, int index, ITypeConverter<?> converter, String value, Class<?> type)
                throws ParameterException {
            try {
                return converter.convert(value);
            } catch (TypeConversionException ex) {
                String msg = String.format("Invalid value for %s: %s", optionDescription("", argSpec, index), ex.getMessage());
                throw new ParameterException(CommandLine.this, msg, ex, argSpec, value);
            } catch (Exception other) {
                String desc = optionDescription("", argSpec, index);
                String msg = String.format("Invalid value for %s: cannot convert '%s' to %s (%s)", desc, value, type.getSimpleName(), other);
                throw new ParameterException(CommandLine.this, msg, other, argSpec, value);
            }
        }
@remkop remkop added this to the 4.5 milestone Jul 16, 2020
@remkop remkop closed this as completed in de8bfca Jul 18, 2020
@remkop remkop modified the milestones: 4.5, 4.4.1 Jul 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant