tschneidereit / SwiftSuspenders

NOTE: Find the offical repo at http://github.com/robotlegs/swiftsuspenders
https://github.com/robotlegs/swiftsuspenders
MIT License
280 stars 89 forks source link

More specific InjectorError sub types #74

Closed Stray closed 11 years ago

Stray commented 11 years ago

Not sure if this is broadly desirable or not, but if I could have slightly more specific errors back from the injector then I'd be able to catch them and feed something useful back to the developer.

Wanted: InjectorAttemptedInterfaceConstructionError

Use case: user does the following -

viewProcessorMap.map(SomeView).toProcess(ISkinProcess);

They would then also need to provide a mapping for ISkinProcess elsewhere. Otherwise, when I do

injector.getInstance(processClass);

they'll see an injector error which is perhaps less useful than the one I could provide if I could specifically catch this 'tried to instantiate an interface' error and then throw one that refers to the specific mapping and the viewProcessorMap.

My other option is to catch all InjectorErrors, parse the error message, check whether it's the one I wanted and then re-throw if not... but I'd prefer not to do that.

What do you think?

tschneidereit commented 11 years ago

Sounds good to me. Depending on how much of a priority you think it is, you might want to consider sending me a pull request, though ;)

Stray commented 11 years ago

I would be delighted - I can add the errors I want this weekend. :)

tschneidereit commented 11 years ago

I would be delighted - I can add the errors I want this weekend. :)

Great, add away :)

tschneidereit commented 11 years ago

Fixed by c24b1cbf9e and 4ea342ccaa