Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 362902 - Uncaught ValueConverterException
Summary: Uncaught ValueConverterException
Status: CLOSED FIXED
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: unspecified   Edit
Hardware: Macintosh Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: M5   Edit
Assignee: Holger Schill CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-04 09:14 EDT by Oliver Reinhard CLA
Modified: 2017-09-19 17:52 EDT (History)
3 users (show)

See Also:
sebastian.zarnekow: juno+


Attachments
Screenshot of pop-up alert (44.91 KB, image/png)
2011-11-04 12:56 EDT, Oliver Reinhard CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Oliver Reinhard CLA 2011-11-04 09:14:30 EDT
Build Identifier: M20110909-1335

When using a terminal rule in a cross reference (CrossReferenceTerminal) to which a ValueConverter is bound, any ValueConverterExceptions thrown by that value converter are propagated up to the Xtext editor an appear as a "Problem Occurred" pop-up alert rather than as an error marker.

As per the contract of IValueConverter, the ValueConverterException is part of the contract. A 

ValueConverterExceptions thrown by the same value converter for a standard terminal-rule invocation is correctly converted to an error marker.

Reproducible: Always

Steps to Reproduce:
1. Create a default MyDsl Xtext project
2. Use this grammar for MyDsl.xtext:
------------------ 
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore

Model:
	greetings+=Greeting*
	'favourite' favourite=[Greeting|MyId];
	
Greeting:
	'Hello' name=MyId '!';
	
MyId returns ecore::EString :
	ID;
------------------ 

3. Create a ValueConverterService like this:
------------------ 
package org.xtext.example.mydsl;

import org.eclipse.xtext.common.services.DefaultTerminalConverters;
import org.eclipse.xtext.conversion.IValueConverter;
import org.eclipse.xtext.conversion.ValueConverter;
import org.eclipse.xtext.conversion.ValueConverterException;
import org.eclipse.xtext.nodemodel.INode;

public class MyDslValueConverterService extends DefaultTerminalConverters {

	@ValueConverter(rule = "MyId")
	public IValueConverter<String> ID() {
		return new IValueConverter<String>() {

			@Override
			public String toValue(String string, INode node) throws ValueConverterException {
				if( string != null && string.length() > 3) {
					throw new ValueConverterException("ID too long", node, null);
				}
				return string;
			}

			@Override
			public String toString(String value) throws ValueConverterException {
				return value;
			}
		};
	}
}
------------------ 

4. Make a Guice binding for the service

5. Start a runtime workbench

6. Enter this text
------------------ 
Hello max !
Hello peter! 
favourite peter
------------------ 

Correctly, an error marker is created for the first occurence of "peter", but an exception window pops up for the second occurrence:
------------------ 
An internal error occurred during: "Xtext validation".
org.eclipse.xtext.linking.impl.IllegalNodeException: org.eclipse.xtext.conversion.ValueConverterException: ID too long
Comment 1 Oliver Reinhard CLA 2011-11-04 12:56:11 EDT
Created attachment 206476 [details]
Screenshot of pop-up alert
Comment 2 Holger Schill CLA 2012-01-03 10:42:31 EST
pushed test and fix to master.
Comment 3 Karsten Thoms CLA 2017-09-19 17:41:03 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 4 Karsten Thoms CLA 2017-09-19 17:52:12 EDT
Closing all bugs that were set to RESOLVED before Neon.0