Request: throw error on autowired DI beans containing syntax errors. #394

Closed
mjhagen opened this Issue Oct 30, 2015 · 14 comments

Comments

Projects
None yet
2 participants
@mjhagen
Contributor

mjhagen commented Oct 30, 2015

I have a controller with a property pointing to a service bean that has a syntax error in it. The framework doesn't throw this error, it just doesn't set the property. Later on I get an exception about the missing variable, but I would like it to show me where the syntax error occurred.

I've written some code that demonstrates this here: https://github.com/mjhagen/SSCCE/tree/master/fw1-394

It has two actions: ?action=main.default and ?action=main.exception, the last one results in "Variable BREAKSTUFFSERVICE is undefined."

@seancorfield

This comment has been minimized.

Show comment
Hide comment
@seancorfield

seancorfield Oct 30, 2015

Member

Are you sure your controller is managed by DI/1? If you call beanfactory.load() that will force all beans to load and you should get syntax errors shown.

If your controller is not managed by DI/1 then it's FW/1 doing the auto wiring and it's possible that swallows exceptions.

Member

seancorfield commented Oct 30, 2015

Are you sure your controller is managed by DI/1? If you call beanfactory.load() that will force all beans to load and you should get syntax errors shown.

If your controller is not managed by DI/1 then it's FW/1 doing the auto wiring and it's possible that swallows exceptions.

@mjhagen

This comment has been minimized.

Show comment
Hide comment
@mjhagen

mjhagen Oct 30, 2015

Contributor

I think it's an FW/1 thing, but I must say I'm still very much a novice if it comes to anything DI.
The app is setup with only framework.diLocations and an autowired bean in the main controller, no beanfactory.load().

Contributor

mjhagen commented Oct 30, 2015

I think it's an FW/1 thing, but I must say I'm still very much a novice if it comes to anything DI.
The app is setup with only framework.diLocations and an autowired bean in the main controller, no beanfactory.load().

@seancorfield

This comment has been minimized.

Show comment
Hide comment
@seancorfield

seancorfield Oct 30, 2015

Member

What's in diLocations?

Member

seancorfield commented Oct 30, 2015

What's in diLocations?

@mjhagen

This comment has been minimized.

Show comment
Hide comment
@mjhagen

mjhagen Oct 30, 2015

Contributor

variables.framework.diLocations = "services";

Contributor

mjhagen commented Oct 30, 2015

variables.framework.diLocations = "services";

@seancorfield

This comment has been minimized.

Show comment
Hide comment
@seancorfield

seancorfield Oct 30, 2015

Member

OK, then your controllers are not managed by DI/1 and this is FW/1's old autowiring code that's hiding the syntax error.

Change that to variables.framework.diLocations = "controllers, services"; and see if you get the syntax error?

Member

seancorfield commented Oct 30, 2015

OK, then your controllers are not managed by DI/1 and this is FW/1's old autowiring code that's hiding the syntax error.

Change that to variables.framework.diLocations = "controllers, services"; and see if you get the syntax error?

@seancorfield

This comment has been minimized.

Show comment
Hide comment
@seancorfield

seancorfield Oct 30, 2015

Member

(sorry for the questions, I didn't notice that your link was to a complete app until just now)

Member

seancorfield commented Oct 30, 2015

(sorry for the questions, I didn't notice that your link was to a complete app until just now)

@mjhagen

This comment has been minimized.

Show comment
Hide comment
@mjhagen

mjhagen Oct 30, 2015

Contributor

Changed it, but it doesn't throw the error. The syntax error is in services/breakstuff.cfc btw.

Contributor

mjhagen commented Oct 30, 2015

Changed it, but it doesn't throw the error. The syntax error is in services/breakstuff.cfc btw.

@seancorfield

This comment has been minimized.

Show comment
Hide comment
@seancorfield

seancorfield Oct 30, 2015

Member

Thanks for double-checking. Will clone your repo and take a deeper look this weekend.

Member

seancorfield commented Oct 30, 2015

Thanks for double-checking. Will clone your repo and take a deeper look this weekend.

@seancorfield seancorfield added this to the 4.0 milestone Oct 30, 2015

@seancorfield seancorfield self-assigned this Oct 30, 2015

@mjhagen

This comment has been minimized.

Show comment
Hide comment
@mjhagen

mjhagen Oct 30, 2015

Contributor

👍

Contributor

mjhagen commented Oct 30, 2015

👍

@seancorfield

This comment has been minimized.

Show comment
Hide comment
@seancorfield

seancorfield Oct 31, 2015

Member

When I run that, I get:

FW/1 version: 4.0.0-snapshot

Framework reloaded: false

Test result: Works!
Member

seancorfield commented Oct 31, 2015

When I run that, I get:

FW/1 version: 4.0.0-snapshot

Framework reloaded: false

Test result: Works!
@seancorfield

This comment has been minimized.

Show comment
Hide comment
@seancorfield

seancorfield Oct 31, 2015

Member

I edited Application.cfc to remove controllers from diLocations, restarted Lucee 4.5.2, and it still worked.

What version of FW/1 are you on? What CFML engine / version?

Member

seancorfield commented Oct 31, 2015

I edited Application.cfc to remove controllers from diLocations, restarted Lucee 4.5.2, and it still worked.

What version of FW/1 are you on? What CFML engine / version?

@mjhagen

This comment has been minimized.

Show comment
Hide comment
@mjhagen

mjhagen Oct 31, 2015

Contributor

CF11 (and FW/1 v4), I provided 2 actions, one that results in the "Works" message, the other (action=main.exception) wich results in the (wrong-ish) error

Contributor

mjhagen commented Oct 31, 2015

CF11 (and FW/1 v4), I provided 2 actions, one that results in the "Works" message, the other (action=main.exception) wich results in the (wrong-ish) error

@seancorfield

This comment has been minimized.

Show comment
Hide comment
@seancorfield

seancorfield Oct 31, 2015

Member

Ah, that was not clear. Thanks. Will try that.

Member

seancorfield commented Oct 31, 2015

Ah, that was not clear. Thanks. Will try that.

seancorfield added a commit that referenced this issue Oct 31, 2015

Fix #394 by actually throwing an exception!
The code was in place to catch and wrap an exception such as this in
order to make it easier to debug. Unfortunately it was missing the
actual throw statement!

I also tidied up the reporting from exceptions that occur when trying to
get a component's metadata: it now attempts to give you the template and
line number where the underlying error occurred.
@seancorfield

This comment has been minimized.

Show comment
Hide comment
@seancorfield

seancorfield Oct 31, 2015

Member

Here's the exception you would get now:

Problem with metadata for breakstuff (tests.SSCCE.fw1-394.services.breakstuff) because: Unable to getComponentMetadata(tests.SSCCE.fw1-394.services.breakstuff) because: Syntax Error, Invalid Construct, near line 3 in /Developer/workspace/fw1/tests/SSCCE/fw1-394/services/breakstuff.cfc

Member

seancorfield commented Oct 31, 2015

Here's the exception you would get now:

Problem with metadata for breakstuff (tests.SSCCE.fw1-394.services.breakstuff) because: Unable to getComponentMetadata(tests.SSCCE.fw1-394.services.breakstuff) because: Syntax Error, Invalid Construct, near line 3 in /Developer/workspace/fw1/tests/SSCCE/fw1-394/services/breakstuff.cfc

seancorfield added a commit that referenced this issue Apr 6, 2016

Fix #394 by actually throwing an exception!
The code was in place to catch and wrap an exception such as this in
order to make it easier to debug. Unfortunately it was missing the
actual throw statement!

I also tidied up the reporting from exceptions that occur when trying to
get a component's metadata: it now attempts to give you the template and
line number where the underlying error occurred.

seancorfield added a commit that referenced this issue Apr 6, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment