I'm not sure if this is a bug or an attempt by Col...
# box-products
b
I'm not sure if this is a bug or an attempt by ColdBox to show errors one way in dev and another way in prod. Hopefully someone has some insight on how to get around this. In the coldbox rest skeleton, If my "ENVIRONMENT" env var is "production", then my exceptionHandler is not being used. If I change to "development", it works as expected. To reproduce it, •
coldbox create app name=cbtest --noinit skeleton=rest
• Coldbox.cfc already has Echo.onError as the exceptionHandler so just add
onError = () => { dump("I'm the echo.fc onError method"); abort; }
to Echo.cfc • Then just throw an error somewhere... like echo.cfc index() With ENVIRONMENT=development, you get the onError dump. With ENVIRONMENT=production, you get the core rest response packet (even if you have extended/replaced it with your own) it doesn't make a difference if it is the global exception handler or an onException interceptor, the result is the same.
w
The coldbox.system.RESTHandler has some special handling for a development environment. e.g
Copy code
// If in development and not in testing mode, then show exception template, easier to debug
        if (
            getSetting( "environment" ) eq "development" && !isInstanceOf(
                variables.controller,
                "MockController"
            )
        ) {
            throw( object = arguments.exception );
        }
Copy code
// Development additions Great for Testing
        if ( getSetting( "environment" ) eq "development" ) {
            prc.response
                .setData( structKeyExists( arguments.exception, "tagContext" ) ? arguments.exception.tagContext : {} )
                .addMessage( "Detail: #arguments.exception.detail#" )
                .addMessage( "StackTrace: #arguments.exception.stacktrace#" );
        }
and there is more. Just search for
getSetting( "environment" )
in this file
I think I don’t like it too much. There is nothing what prevents you from calling your development environment
dev
or something totally different.
development
is not a reserved name. The only environment name which is fixed is
production
because that’s the default. Although it is very descriptive to use
development
of course.
Nonetheless some of these extra functionality for development can be very handy. As long as it it documented. What I noticed recently: the best way to find out what’s going on is by reading the source code. The official docs are often incomplete or sometimes incorrect, which is not so shocking for a huge framework like this.
b
Sorry, @wil-shiftinsert, I had to bail shortly after posting yesterday. I guess my search was bad because I was looking all over for environment references and didn't see those. You are spot on (as usual when it comes to obscure ColdBox questions). I was able to extend the core RestHandler and override the functionality to suit my needs and all my tests are passing again... regardless of environment. Thanks for the assist.
w
I ❤️ obscure coldbox questions 😄. Glad I could help.
👍 2