@@ -57,10 +57,65 @@ export async function runFunctionAndLog(
57
57
functionArgs ,
58
58
) ;
59
59
} catch ( err ) {
60
+ const errorMessage = ( err as Error ) . toString ( ) . trim ( ) ;
61
+
62
+ if ( errorMessage . includes ( "Could not find function" ) ) {
63
+ const functions = ( await runSystemQuery ( ctx , {
64
+ deploymentUrl : args . deploymentUrl ,
65
+ adminKey : args . adminKey ,
66
+ functionName : "_system/cli/modules:apiSpec" ,
67
+ componentPath : args . componentPath ,
68
+ args : { } ,
69
+ } ) ) as (
70
+ | {
71
+ functionType : "Query" | "Mutation" | "Action" ;
72
+ identifier : string ;
73
+ }
74
+ | {
75
+ functionType : "HttpAction" ;
76
+ }
77
+ ) [ ] ;
78
+
79
+ const functionNames = functions
80
+ . filter (
81
+ (
82
+ fn ,
83
+ ) : fn is {
84
+ functionType : "Query" | "Mutation" | "Action" ;
85
+ identifier : string ;
86
+ } => fn . functionType !== "HttpAction" ,
87
+ )
88
+ . map ( ( { identifier } ) => {
89
+ const separatorPos = identifier . indexOf ( ":" ) ;
90
+
91
+ const path =
92
+ separatorPos === - 1
93
+ ? ""
94
+ : identifier . substring ( 0 , separatorPos + 1 ) ;
95
+ const name =
96
+ separatorPos === - 1
97
+ ? identifier
98
+ : identifier . substring ( separatorPos + 1 ) ;
99
+
100
+ return `• ${ chalk . gray ( path ) } ${ name } ` ;
101
+ } ) ;
102
+
103
+ const availableFunctionsMessage =
104
+ functionNames . length > 0
105
+ ? `Available functions:\n${ functionNames . join ( "\n" ) } `
106
+ : "No functions found." ;
107
+
108
+ return await ctx . crash ( {
109
+ exitCode : 1 ,
110
+ errorType : "invalid filesystem data" ,
111
+ printedMessage : `Failed to run function "${ args . functionName } ":\n${ chalk . red ( errorMessage ) } \n\n${ availableFunctionsMessage } ` ,
112
+ } ) ;
113
+ }
114
+
60
115
return await ctx . crash ( {
61
116
exitCode : 1 ,
62
117
errorType : "invalid filesystem or env vars" ,
63
- printedMessage : `Failed to run function "${ args . functionName } ":\n${ chalk . red ( ( err as Error ) . toString ( ) . trim ( ) ) } ` ,
118
+ printedMessage : `Failed to run function "${ args . functionName } ":\n${ chalk . red ( errorMessage ) } ` ,
64
119
} ) ;
65
120
}
66
121
0 commit comments