Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Configuring Scope Provider Error Handler
icon5.gif  Configuring Scope Provider Error Handler [message #759778] Tue, 29 November 2011 19:44 Go to next message
Mirko Raner is currently offline Mirko Raner
Messages: 79
Registered: July 2009
Location: San Diego, CA
Member
Hi all,

we're trying to debug some tricky scope provider issues and we just noticed that a number of exceptions get silently swallowed because AbstractDeclarativeScopeProvider by default uses a NullErrorHandler. So, we're trying to bind to the following injection point in ADSP:

	@Inject(optional=true)
	@Named(NAMED_ERROR_HANDLER)
	private PolymorphicDispatcher.ErrorHandler<IScope> errorHandler = new PolymorphicDispatcher.NullErrorHandler<IScope>();

Our configure method looks like this, but it's not working (it does get executed, though):

binder.bind(
		((TypeLiteral<PolymorphicDispatcher.ErrorHandler<IScope>>)TypeLiteral.get(Types.newParameterizedType(PolymorphicDispatcher.ErrorHandler.class, IScope.class)))).
				annotatedWith(Names.named(AbstractDeclarativeScopeProvider.NAMED_ERROR_HANDLER)).
				toInstance(new PolymorphicDispatcher.DefaultErrorHandler<IScope>());

When we break in the debugger in our custom scope provider it still shows a NullErrorHandler as the error handler, so apparently the binding didn't take. We configure the binding in the runtime module that goes with our scope provider, but maybe that's too late?
Any idea what we're doing wrong here?

Thanks!
Re: Configuring Scope Provider Error Handler [message #759810 is a reply to message #759778] Wed, 30 November 2011 02:43 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian Zarnekow
Messages: 2809
Registered: July 2009
Senior Member
Mirko,

did you try to bind the error handler as a class instead of the type?
bind(ErrorHandler.class).anoatedWith(...).to(..);

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 30.11.11 01:45, schrieb Mirko Raner:
> Hi all,
>
> we're trying to debug some tricky scope provider issues and we just
> noticed that a number of exceptions get silently swallowed because
> AbstractDeclarativeScopeProvider by default uses a NullErrorHandler. So,
> we're trying to bind to the following injection point in ADSP:
>
> @Inject(optional=true)
> @Named(NAMED_ERROR_HANDLER)
> private PolymorphicDispatcher.ErrorHandler<IScope> errorHandler = new
> PolymorphicDispatcher.NullErrorHandler<IScope>();
> Our configure method looks like this, but it's not working (it does get
> executed, though):
>
> binder.bind(
> ((TypeLiteral<PolymorphicDispatcher.ErrorHandler<IScope>>)TypeLiteral.get(Types.newParameterizedType(PolymorphicDispatcher.ErrorHandler.class,
> IScope.class)))).
> annotatedWith(Names.named(AbstractDeclarativeScopeProvider.NAMED_ERROR_HANDLER)).
>
> toInstance(new PolymorphicDispatcher.DefaultErrorHandler<IScope>());
> When we break in the debugger in our custom scope provider it still
> shows a NullErrorHandler as the error handler, so apparently the binding
> didn't take. We configure the binding in the runtime module that goes
> with our scope provider, but maybe that's too late?
> Any idea what we're doing wrong here?
> Thanks!
>
Re: Configuring Scope Provider Error Handler [message #897735 is a reply to message #759810] Wed, 25 July 2012 03:51 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian Zarnekow
Messages: 2809
Registered: July 2009
Senior Member
For the sake of completeness: This one will do the trick:

public void configureErrorHandler(Binder binder) {
		binder.bind(new TypeLiteral<PolymorphicDispatcher.ErrorHandler<IScope>>() {}).annotatedWith(
				Names.named(AbstractDeclarativeScopeProvider.NAMED_ERROR_HANDLER)).to(MyErrorHandler.class);
	}
	
	static class MyErrorHandler extends PolymorphicDispatcher.DefaultErrorHandler<IScope> {
		public MyErrorHandler() {
			System.out.println("initialized custom error handler");
		}
	}


[Updated on: Wed, 25 July 2012 03:52]

Report message to a moderator

Re: Configuring Scope Provider Error Handler [message #897765 is a reply to message #759810] Wed, 25 July 2012 04:39 Go to previous messageGo to next message
Aaron Digulla is currently offline Aaron Digulla
Messages: 258
Registered: July 2009
Location: Switzerland
Senior Member
To bind this in Xtext 2.3.0, use this code:

    public void configureErrorHandler(Binder binder) {
        Logger logger = Logger.getLogger(PolymorphicDispatcher.class);
        PolymorphicDispatcher.ErrorHandler<IScope> handler = PolymorphicDispatcher.WarningErrorHandler.get( logger );
        
        binder.bind(new TypeLiteral<PolymorphicDispatcher.ErrorHandler<IScope>>(){})
        .annotatedWith(Names.named(AbstractDeclarativeScopeProvider.NAMED_ERROR_HANDLER))
        .toInstance( handler )
        ;
    }


but there is a catch: You will get many exceptions of type NoSuchMethodException. To fix that, use this error handler:

import org.apache.log4j.Logger;
import org.eclipse.xtext.util.PolymorphicDispatcher.ErrorHandler;

public class PolymorphicDispatcherErrorHandler<RT> implements ErrorHandler<RT> {

    private Logger logger;

    public PolymorphicDispatcherErrorHandler( Logger logger ) {
        this.logger = logger;
    }
    
    @Override
    public RT handle( Object[] params, Throwable throwable ) {
        
        if( !(throwable instanceof NoSuchMethodException ) ) {
            logger.warn("Error in polymorphic dispatcher : "+throwable.getMessage(), throwable);
        }
        
        return null;
    }

    
}


Replace "PolymorphicDispatcher.WarningErrorHandler.get" with "new PolymorphicDispatcherErrorHandler<IScope>" to use it.

Regards,

A. Digulla
Re: Configuring Scope Provider Error Handler [message #1062776 is a reply to message #897765] Mon, 10 June 2013 13:06 Go to previous messageGo to next message
Michael Vorburger is currently offline Michael Vorburger
Messages: 62
Registered: July 2009
Member
Thank you for this post - very useful. Q: Is there any particular reason something like this WarningErrorHandlerWithoutNoSuchMethodException is not used by default in the AbstractDeclarativeScopeProvider instead of the current NullErrorHandler? That would make finding some problems in your own ScopeProvider easier out-of-the-box - without having to apply this. Bugzilla?
Re: Configuring Scope Provider Error Handler [message #1063878 is a reply to message #1062776] Fri, 14 June 2013 12:40 Go to previous message
Aaron Digulla is currently offline Aaron Digulla
Messages: 258
Registered: July 2009
Location: Switzerland
Senior Member
My feeling is that the code is designed to fail silently in production. Unfortunately, this makes development of Xtext DSLs harder than it needs to be.

I would like to see a "development mode" for DSLs where these are disabled. If you like the idea, raise your voice: https://bugs.eclipse.org/bugs/show_bug.cgi?id=407874
Previous Topic:Xtend 2.4.2 and static method access (regression?)
Next Topic:How can i change Imported Meta-model
Goto Forum:
  


Current Time: Thu Jul 31 15:48:45 EDT 2014

Powered by FUDForum. Page generated in 0.05405 seconds