Skip to content

Commit b6db607

Browse files
colerogerstaeold
andauthored
Add user-friendly warning for runtime errors from the GCF API (#8713)
* add warning for any runtime errors from GCF api * add changelog * making helper for regex capture --------- Co-authored-by: Daniel Lee <[email protected]>
1 parent 2c576e6 commit b6db607

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
- Added validation to check if project ID exists during project creation. (#5233)
22
- Add `generate_dataconnect_schema`, `dataconnect_generate_operation`, `firebase_consult_assistant` MCP tools. (#8647)
33
- `firebase init dataconnect` is now integrated with Gemini in Firebase API to generate Schema based on description. (#8596)
4+
- Add user-friendly warning for runtime errors from the GCF API. (#8713)

src/gcp/cloudfunctions.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,41 @@ export interface CloudFunction {
145145

146146
export type OutputOnlyFields = "status" | "buildId" | "updateTime" | "versionId";
147147

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 = /message: "((?:\\.|[^"\\])*)"/;
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+
148169
/**
149170
* Logs an error from a failed function deployment.
150171
* @param funcName Name of the function that was unsuccessfully deployed.
151172
* @param type Type of deployment - create, update, or delete.
152173
* @param err The error returned from the operation.
153174
*/
154175
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+
}
155183
if (err?.context?.response?.statusCode === 429) {
156184
utils.logWarning(
157185
`${clc.bold(

src/gcp/cloudfunctionsv2.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
HASH_LABEL,
1818
} from "../functions/constants";
1919
import { RequireKeys } from "../metaprogramming";
20+
import { captureRuntimeValidationError } from "./cloudfunctions";
2021

2122
export const API_VERSION = "v2";
2223

@@ -250,6 +251,11 @@ export function mebibytes(memory: string): number {
250251
* @param err The error returned from the operation.
251252
*/
252253
function functionsOpLogReject(func: InputCloudFunction, type: string, err: any): void {
254+
// Sniff for runtime validation errors and log a more user-friendly warning.
255+
if (err?.message?.includes("Runtime validation errors")) {
256+
const capturedMessage = captureRuntimeValidationError(err.message);
257+
utils.logLabeledWarning("functions", capturedMessage + " for function " + func.name);
258+
}
253259
if (err?.message?.includes("maxScale may not exceed")) {
254260
const maxInstances = func.serviceConfig.maxInstanceCount || DEFAULT_MAX_INSTANCE_COUNT;
255261
utils.logLabeledWarning(

0 commit comments

Comments
 (0)