Skip to content

Commit c3fcc2c

Browse files
elpetelmajano
authored andcommitted
Better error messages for ColdBox module setting injections (#608)
1 parent 03f1e5f commit c3fcc2c

File tree

2 files changed

+27
-20
lines changed

2 files changed

+27
-20
lines changed

system/ioc/dsl/ColdBoxDSL.cfc

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -175,27 +175,34 @@ component accessors="true" {
175175
// module setting?
176176
if ( find( "@", thisLocationKey ) ) {
177177
moduleSettings = variables.coldbox.getSetting( "modules" );
178-
if (
179-
structKeyExists( moduleSettings, listLast( thisLocationKey, "@" ) )
180-
and structKeyExists(
181-
moduleSettings[ listLast( thisLocationKey, "@" ) ],
182-
"settings"
183-
)
184-
and structKeyExists(
185-
moduleSettings[ listLast( thisLocationKey, "@" ) ].settings,
186-
listFirst( thisLocationKey, "@" )
187-
)
188-
) {
189-
return moduleSettings[ listLast( thisLocationKey, "@" ) ].settings[
190-
listFirst( thisLocationKey, "@" )
191-
];
192-
} else {
178+
var moduleName = listLast( thisLocationKey, "@" );
179+
if ( !structKeyExists( moduleSettings, moduleName ) ) {
180+
throw(
181+
type = "ColdBoxDSL.InvalidDSL",
182+
message = "The DSL provided was not valid: #arguments.definition.toString()#",
183+
detail = "The module requested: #moduleName# does not exist in the loaded modules. Loaded modules are #structKeyList( moduleSettings )#"
184+
);
185+
}
186+
187+
if ( !structKeyExists( moduleSettings[ moduleName ], "settings" ) ) {
193188
throw(
194189
type = "ColdBoxDSL.InvalidDSL",
195190
message = "The DSL provided was not valid: #arguments.definition.toString()#",
196-
detail = "The module requested: #listLast( thisLocationKey, "@" )# does not exist in the loaded modules. Loaded modules are #structKeyList( moduleSettings )#"
191+
detail = "The module requested: #moduleName# does not have any settings defined."
197192
);
198193
}
194+
195+
var settingName = listFirst( thisLocationKey, "@" )
196+
197+
if ( !structKeyExists( moduleSettings[ moduleName ].settings, settingName ) ) {
198+
throw(
199+
type = "ColdBoxDSL.InvalidDSL",
200+
message = "The DSL provided was not valid: #arguments.definition.toString()#",
201+
detail = "The module requested: #moduleName# does not have the setting [#settingName#] defined. Available settings are: [#moduleSettings[ moduleName ].settings.keyList( ", " )#]"
202+
);
203+
}
204+
205+
return moduleSettings[ moduleName ].settings[ settingName ];
199206
}
200207
// just get setting
201208
return variables.coldbox.getSetting( thisLocationKey );

tests/specs/ioc/dsl/ColdBoxDSLTest.cfc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<cfcomponent extends="coldbox.system.testing.BaseModelTest">
2-
<cfscript>
1+
component extends="coldbox.system.testing.BaseModelTest" {
2+
33
function setup(){
44
mockLogger = createEmptyMock( "coldbox.system.logging.Logger" )
55
.$( "canDebug", true )
@@ -184,5 +184,5 @@
184184
c = builder.getColdBoxDSL( def );
185185
assertEquals( this, c );
186186
}
187-
</cfscript>
188-
</cfcomponent>
187+
188+
}

0 commit comments

Comments
 (0)