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

Bad error Message from INTValueConverter #2576

Open
cdietrich opened this issue Jan 16, 2017 · 12 comments
Open

Bad error Message from INTValueConverter #2576

cdietrich opened this issue Jan 16, 2017 · 12 comments

Comments

@cdietrich
Copy link
Member

a failing INTValueConverter leeds to following error message

For input string: "999999999999999999999"

it would be nice to have better error messages

@cdietrich
Copy link
Member Author

"Bad" Conversion is done by
org.eclipse.xtext.parser.antlr.SyntaxErrorMessageProvider.getSyntaxErrorMessage(IValueConverterErrorContext) calling org.eclipse.xtext.parser.antlr.AbstractInternalAntlrParser.getValueConverterExceptionMessage(ValueConverterException)

@cdietrich
Copy link
Member Author

i am not sure if this should be fixed on ValueConverter side or on SyntaxErrorMessageProvider side

@JanKoehnlein
Copy link
Contributor

I'd say in the value converter. It is closer to the problem implementation-wise. I see SyntaxErrorMessageProvider more as a customization point for overriding defaults.

@cdietrich
Copy link
Member Author

cdietrich commented Feb 21, 2017

as i said: the value converter message is fine,
but the other guys ignore its message and return the root cause

throw new ValueConverterException("Couldn't convert '" + string + "' to an int value.", node, e);

so we should not attach the root cause there?

here is what the parser does

	protected String getValueConverterExceptionMessage(ValueConverterException vce) {
		Exception cause = (Exception) vce.getCause();
		String result = cause != null ? cause.getMessage() : vce.getMessage();
		if (result == null)
			result = vce.getMessage();
		if (result == null)
			result = cause != null ? cause.getClass().getSimpleName() : vce.getClass().getSimpleName();
		return result;
	}

@cdietrich
Copy link
Member Author

any hints?

@szarnekow
Copy link
Contributor

I think the vce's message should win if it's not the default message.

@cdietrich
Copy link
Member Author

hmmm a valueconverter exception is constructed as follows

	public ValueConverterException(String message, INode node, Exception cause) {
		super(message == null && cause != null ? cause.getMessage() : message, cause);
		this.node = node;
	}

=> the exception message contains the causes message if there was no explicit message

@szarnekow
Copy link
Contributor

Meh. Comparing the causes' message with the value converters message doesn't make any sense in getValueConverterExceptionMessage so we should just use the message of the vce.

tkutz referenced this issue in itemisCREATE/statecharts Feb 7, 2019
When Xtext cannot parse an int literal, it gives a meaningless "For input string: ..." error message, although the value converter exception carries a proper error message with it. See also https://github.com/eclipse/xtext-core/issues/247.
andreasmuelder referenced this issue in itemisCREATE/statecharts Feb 11, 2019
* Fix binding to ISyntaxErrorMessageProvider

* Improve error message for large integer values

When Xtext cannot parse an int literal, it gives a meaningless "For input string: ..." error message, although the value converter exception carries a proper error message with it. See also https://github.com/eclipse/xtext-core/issues/247.
@miklossy miklossy added this to the Release_2.21 milestone Nov 24, 2019
@cdietrich
Copy link
Member Author

@miklossy do you plan to work on this issue?

@miklossy
Copy link
Contributor

Not in the near future. I will unset the milestone.

@miklossy miklossy removed this from the Release_2.21 milestone Feb 21, 2020
@cdietrich cdietrich transferred this issue from eclipse/xtext-core Apr 18, 2023
@dpetroff
Copy link

This error message is a really great way to waste a morning debugging the parser and pulling at your hair when you change some rule names in the grammar and forget that somebody wrote custom value converters 2 years ago.

@cdietrich
Copy link
Member Author

pull request still is welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants