@@ -145,13 +145,41 @@ export interface CloudFunction {
145
145
146
146
export type OutputOnlyFields = "status" | "buildId" | "updateTime" | "versionId" ;
147
147
148
+ /**
149
+ * Returns the captured user-friendly message from a runtime validation error.
150
+ * @param errMessage Message from the runtime validation error.
151
+ */
152
+ export function captureRuntimeValidationError ( errMessage : string ) : string {
153
+ // Regex to capture the content of the 'message' field.
154
+ // The error messages will take this form:
155
+ // `Failed to create 1st Gen function projects/p/locations/l/functions/f:
156
+ // runtime: Runtime validation errors: [error_code: INVALID_RUNTIME\n
157
+ // message: \"Runtime \\\"nodejs22\\\" is not supported on GCF Gen1\"\n]`
158
+ const regex = / m e s s a g e : " ( (?: \\ .| [ ^ " \\ ] ) * ) " / ;
159
+ const match = errMessage . match ( regex ) ;
160
+ if ( match && match [ 1 ] ) {
161
+ // The captured string may still contain escaped quotes (e.g., \\").
162
+ // This replaces them with a standard double quote.
163
+ const capturedMessage = match [ 1 ] . replace ( / \\ " / g, '"' ) ;
164
+ return capturedMessage ;
165
+ }
166
+ return "invalid runtime detected, please see https://cloud.google.com/functions/docs/runtime-support for the latest supported runtimes" ;
167
+ }
168
+
148
169
/**
149
170
* Logs an error from a failed function deployment.
150
171
* @param funcName Name of the function that was unsuccessfully deployed.
151
172
* @param type Type of deployment - create, update, or delete.
152
173
* @param err The error returned from the operation.
153
174
*/
154
175
function functionsOpLogReject ( funcName : string , type : string , err : any ) : void {
176
+ // Sniff for runtime validation errors and log a more user-friendly warning.
177
+ if ( ( err ?. message as string ) . includes ( "Runtime validation errors" ) ) {
178
+ const capturedMessage = captureRuntimeValidationError ( err . message ) ;
179
+ utils . logWarning (
180
+ clc . bold ( clc . yellow ( "functions:" ) ) + " " + capturedMessage + " for function " + funcName ,
181
+ ) ;
182
+ }
155
183
if ( err ?. context ?. response ?. statusCode === 429 ) {
156
184
utils . logWarning (
157
185
`${ clc . bold (
0 commit comments