File tree 2 files changed +25
-14
lines changed
2 files changed +25
-14
lines changed Original file line number Diff line number Diff line change @@ -93,7 +93,11 @@ export async function getUserFunction(
93
93
try {
94
94
const functionModulePath = getFunctionModulePath ( codeLocation ) ;
95
95
if ( functionModulePath === null ) {
96
- console . error ( 'Provided code is not a loadable module.' ) ;
96
+ console . error (
97
+ `Provided code location '${ codeLocation } ' is not a loadable module.` +
98
+ '\nDid you specify the correct location for the module defining ' +
99
+ 'your function?'
100
+ ) ;
97
101
return null ;
98
102
}
99
103
@@ -174,16 +178,17 @@ export async function getUserFunction(
174
178
* @return Resolved path or null.
175
179
*/
176
180
function getFunctionModulePath ( codeLocation : string ) : string | null {
177
- let path : string | null = null ;
178
181
try {
179
- path = require . resolve ( codeLocation ) ;
182
+ return require . resolve ( codeLocation ) ;
180
183
} catch ( ex ) {
181
- try {
182
- // TODO: Decide if we want to keep this fallback.
183
- path = require . resolve ( codeLocation + '/function.js' ) ;
184
- } catch ( ex ) {
185
- return path ;
186
- }
184
+ // Ignore exception, this means the function was not found here.
185
+ }
186
+
187
+ try {
188
+ return require . resolve ( codeLocation + '/function.js' ) ;
189
+ } catch ( ex ) {
190
+ // Ignore exception, this means the function was not found here.
187
191
}
188
- return path ;
192
+
193
+ return null ;
189
194
}
Original file line number Diff line number Diff line change @@ -93,11 +93,17 @@ describe('loading function', () => {
93
93
}
94
94
}
95
95
96
- it ( 'fails to load a function that does not exist' , async ( ) => {
97
- FunctionRegistry . http ( 'function' , ( ) => {
98
- return 'PASS' ;
99
- } ) ;
96
+ it ( 'fails to load a module that does not exist' , async ( ) => {
97
+ const loadedFunction = await loader . getUserFunction (
98
+ process . cwd ( ) + '/test/data/does_not_exist' ,
99
+ 'functionDoesNotExist' ,
100
+ 'http'
101
+ ) ;
100
102
103
+ assert . strictEqual ( loadedFunction , null ) ;
104
+ } ) ;
105
+
106
+ it ( 'fails to load a function that does not exist' , async ( ) => {
101
107
const loadedFunction = await loader . getUserFunction (
102
108
process . cwd ( ) + '/test/data/with_main' ,
103
109
'functionDoesNotExist' ,
You can’t perform that action at this time.
0 commit comments