Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/emulator/adminSdkConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export async function getProjectAdminSdkConfigOrCached(
const config = await getProjectAdminSdkConfig(projectId);
setCacheAdminSdkConfig(projectId, config);
return config;
} catch (e: any) {
} catch (e: unknown) {
logger.debug(`Failed to get Admin SDK config for ${projectId}, falling back to cache`, e);
return getCachedAdminSdkConfig(projectId);
}
Expand Down Expand Up @@ -71,11 +71,11 @@ async function getProjectAdminSdkConfig(projectId: string): Promise<AdminSdkConf
try {
const res = await apiClient.get<AdminSdkConfig>(`projects/${projectId}/adminSdkConfig`);
return res.body;
} catch (err: any) {
} catch (err: unknown) {
throw new FirebaseError(
`Failed to get Admin SDK for Firebase project ${projectId}. ` +
"Please make sure the project exists and your account has permission to access it.",
{ exit: 2, original: err },
{ exit: 2, original: err instanceof Error ? err : new Error(String(err)) },
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/emulator/auth/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1642,7 +1642,7 @@ async function signInWithIdp(
userMatchingProvider,
));
}
} catch (err: any) {
} catch (err: unknown) {
if (reqBody.returnIdpCredential && err instanceof BadRequestError) {
response.errorMessage = err.message;
return response;
Expand Down
14 changes: 8 additions & 6 deletions src/emulator/commandUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ export async function beforeEmulatorCommand(options: any): Promise<any> {
) {
try {
await requireAuth(options);
} catch (e: any) {
logger.debug(e);
} catch (e: unknown) {
logger.debug(e as any);
Comment thread
joehan marked this conversation as resolved.
utils.logLabeledWarning(
"emulators",
`You are not currently authenticated so some features may not work correctly. Please run ${clc.bold(
Expand Down Expand Up @@ -333,8 +333,8 @@ function processKillSignal(
}
}
res();
} catch (e: any) {
logger.debug(e);
} catch (e: unknown) {
logger.debug(e as any);
Comment thread
joehan marked this conversation as resolved.
rej();
}
};
Expand Down Expand Up @@ -512,9 +512,11 @@ export async function checkJavaMajorVersion(): Promise<number> {
stdio: ["inherit", "pipe", "pipe"],
},
);
} catch (err: any) {
} catch (err: unknown) {
return reject(
new FirebaseError(`Could not spawn \`java -version\`. ${JAVA_HINT}`, { original: err }),
new FirebaseError(`Could not spawn \`java -version\`. ${JAVA_HINT}`, {
original: err instanceof Error ? err : new Error(String(err)),
}),
);
}

Expand Down
21 changes: 10 additions & 11 deletions src/emulator/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,12 @@ export function shouldStart(options: Options, name: Emulators): boolean {
try {
normalizeAndValidate(options.config.src.functions);
return true;
} catch (err: any) {
} catch (err: unknown) {
const message = err instanceof Error ? err.message : String(err);
EmulatorLogger.forEmulator(Emulators.FUNCTIONS).logLabeled(
"ERROR",
"functions",
`Failed to start Functions emulator: ${err.message}`,
`Failed to start Functions emulator: ${message}`,
);
return false;
}
Expand Down Expand Up @@ -357,7 +358,7 @@ export async function startAll(
if (!isDemoProject) {
try {
projectNumber = await needProjectNumber(options);
} catch (err: any) {
} catch (err: unknown) {
EmulatorLogger.forEmulator(Emulators.EXTENSIONS).logLabeled(
"ERROR",
Emulators.EXTENSIONS,
Expand Down Expand Up @@ -781,11 +782,9 @@ export async function startAll(
if (!options.instance) {
options.instance = await getDefaultDatabaseInstance(projectId);
}
} catch (e: any) {
databaseLogger.log(
"DEBUG",
`Failed to retrieve default database instance: ${JSON.stringify(e)}`,
);
} catch (e: unknown) {
const message = e instanceof Error ? e.message : String(e);
databaseLogger.log("DEBUG", `Failed to retrieve default database instance: ${message}`);
}

const rc = dbRulesConfig.normalizeRulesConfig(
Expand Down Expand Up @@ -1117,7 +1116,7 @@ export async function exportEmulatorData(exportPath: string, options: any, initi
let origin;
try {
origin = await hubClient.getStatus();
} catch (e: any) {
} catch (e: unknown) {
const filePath = EmulatorHub.getLocatorFilePath(projectId);
throw new FirebaseError(
`The emulator hub for ${projectId} did not respond to a status check. If this error continues try shutting down all running emulators and deleting the file ${filePath}`,
Expand Down Expand Up @@ -1161,10 +1160,10 @@ export async function exportEmulatorData(exportPath: string, options: any, initi
try {
const targets = filterEmulatorTargets(options);
await hubClient.postExport({ path: exportAbsPath, initiatedBy, targets });
} catch (e: any) {
} catch (e: unknown) {
throw new FirebaseError("Export request failed, see emulator logs for more information.", {
exit: 1,
original: e,
original: e instanceof Error ? e : new Error(String(e)),
});
}

Expand Down
23 changes: 14 additions & 9 deletions src/emulator/dataconnectEmulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ export class DataConnectEmulator implements EmulatorInstance {
);
}
}
} catch (err: any) {
this.logger.log("DEBUG", `'fdc build' failed with error: ${err.message}`);
} catch (err: unknown) {
const message = err instanceof Error ? err.message : String(err);
this.logger.log("DEBUG", `'fdc build' failed with error: ${message}`);
}
const env = await DataConnectEmulator.getEnv(this.args.account, this.args.extraEnv);
await start(
Expand Down Expand Up @@ -259,8 +260,8 @@ export class DataConnectEmulator implements EmulatorInstance {
// Handle errors like command not found
reject(err);
});
} catch (e: any) {
if (isIncomaptibleArchError(e)) {
} catch (e: unknown) {
if (isIncomaptibleArchError(e as Error)) {
Comment thread
joehan marked this conversation as resolved.
reject(
new FirebaseError(
`Unknown system error when running the SQL Connect toolkit. ` +
Expand Down Expand Up @@ -343,14 +344,14 @@ export class DataConnectEmulator implements EmulatorInstance {
`Successfully connected to ${connectionString}}`,
);
return true;
} catch (err: any) {
} catch (err: unknown) {
if (i === MAX_RETRIES) {
throw err;
}
this.logger.logLabeled(
"DEBUG",
"SQL Connect",
`Retrying connectToPostgress call (${i} of ${MAX_RETRIES} attempts): ${err}`,
`Retrying connectToPostgress call (${i} of ${MAX_RETRIES} attempts): ${String(err)}`,
);
await new Promise((resolve) => setTimeout(resolve, 2000));
}
Expand Down Expand Up @@ -413,9 +414,13 @@ export class DataConnectEmulatorClient {
body,
);
return res;
} catch (err: any) {
if (err.status === 500) {
throw new FirebaseError(`SQL Connect emulator: ${err?.context?.body?.message}`);
} catch (err: unknown) {
if (typeof err === "object" && err !== null && "status" in err) {
const status = (err as { status: unknown }).status;
if (status === 500) {
const message = (err as any)?.context?.body?.message;
throw new FirebaseError(`SQL Connect emulator: ${message || String(err)}`);
}
}
throw err;
}
Comment thread
joehan marked this conversation as resolved.
Expand Down
2 changes: 1 addition & 1 deletion src/emulator/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export async function downloadEmulator(name: DownloadableEmulators): Promise<voi
let tmpfile: string;
try {
tmpfile = await downloadUtils.downloadToTmp(emulator.opts.remoteUrl, !!emulator.opts.auth);
} catch (err: any) {
} catch (err: unknown) {
if (overrideVersion && err instanceof FirebaseError && err.status === 404) {
throw new FirebaseError(
`env variable ${name.toUpperCase()}_EMULATOR_VERSION set to ${overrideVersion},
Expand Down
38 changes: 22 additions & 16 deletions src/emulator/functionsEmulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -866,10 +866,11 @@ export class FunctionsEmulator implements EmulatorInstance {
);
try {
await this.startRuntime(emulatableBackend);
} catch (e: any) {
} catch (e: unknown) {
const message = e instanceof Error ? e.message : String(e);
this.logger.logLabeled(
"ERROR",
`Failed to start functions in ${emulatableBackend.functionsDir}: ${e}`,
`Failed to start functions in ${emulatableBackend.functionsDir}: ${message}`,
);
}
}
Expand Down Expand Up @@ -1172,8 +1173,8 @@ export class FunctionsEmulator implements EmulatorInstance {
const client = EmulatorRegistry.client(Emulators.DATABASE);
try {
await client.post(apiPath, bundle, { headers: { Authorization: "Bearer owner" } });
} catch (err: any) {
this.logger.log("WARN", "Error adding Realtime Database function: " + err);
} catch (err: unknown) {
this.logger.log("WARN", "Error adding Realtime Database function: " + String(err));
throw err;
}
return true;
Expand Down Expand Up @@ -1246,8 +1247,8 @@ export class FunctionsEmulator implements EmulatorInstance {
const client = EmulatorRegistry.client(Emulators.FIRESTORE);
try {
signature === "cloudevent" ? await client.post(path, bundle) : await client.put(path, bundle);
} catch (err: any) {
this.logger.log("WARN", "Error adding firestore function: " + err);
} catch (err: unknown) {
this.logger.log("WARN", "Error adding firestore function: " + String(err));
throw err;
}
return true;
Expand Down Expand Up @@ -1480,7 +1481,7 @@ export class FunctionsEmulator implements EmulatorInstance {
if (functionsEnv.hasUserEnvs(projectInfo)) {
try {
return functionsEnv.loadUserEnvs(projectInfo);
} catch (e: any) {
} catch (e: unknown) {
// Ignore - user envs are optional.
logger.debug("Failed to load local environment variables", e);
}
Expand Down Expand Up @@ -1578,13 +1579,17 @@ export class FunctionsEmulator implements EmulatorInstance {
try {
const data = fs.readFileSync(secretPath, "utf8");
secretEnvs = functionsEnv.parseStrict(data);
} catch (e: any) {
if (e.code !== "ENOENT") {
this.logger.logLabeled(
"ERROR",
"functions",
`Failed to read local secrets file ${secretPath}: ${e.message}`,
);
} catch (e: unknown) {
if (typeof e === "object" && e !== null && "code" in e) {
const code = (e as { code: unknown }).code;
if (code !== "ENOENT") {
const message = e instanceof Error ? e.message : String(e);
this.logger.logLabeled(
"ERROR",
"functions",
`Failed to read local secrets file ${secretPath}: ${message}`,
);
}
}
}
Comment thread
joehan marked this conversation as resolved.
// Note - if trigger is undefined, we are loading in 'sequential' mode.
Expand Down Expand Up @@ -1945,11 +1950,12 @@ export class FunctionsEmulator implements EmulatorInstance {
if (!pool.readyForWork(trigger.id, record.backend.runtime)) {
try {
await this.startRuntime(record.backend, trigger);
} catch (e: any) {
} catch (e: unknown) {
const message = e instanceof Error ? e.message : String(e);
this.logger.logLabeled("ERROR", `Failed to handle request for function ${trigger.id}`);
this.logger.logLabeled(
"ERROR",
`Failed to start functions in ${record.backend.functionsDir}: ${e}`,
`Failed to start functions in ${record.backend.functionsDir}: ${message}`,
);
return;
}
Expand Down
43 changes: 27 additions & 16 deletions src/emulator/functionsEmulatorRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
return new Promise((res, rej) => {
try {
res(require(require.resolve(moduleName, opts))); // eslint-disable-line @typescript-eslint/no-var-requires
} catch (e: any) {
} catch (e: unknown) {
rej(e);
}
});
Expand All @@ -51,7 +51,7 @@
return new Promise((res, rej) => {
try {
res(require.resolve(moduleName, opts));
} catch (e: any) {
} catch (e: unknown) {
rej(e);
}
});
Expand Down Expand Up @@ -289,7 +289,7 @@
devDependencies: pkg.devDependencies || {},
};
return developerPkgJSON;
} catch (err: any) {
} catch (err: unknown) {
return;
}
}
Expand Down Expand Up @@ -335,7 +335,7 @@
try {
new URL(arg);
return arg;
} catch (err: any) {
} catch (err: unknown) {
return;
}
} else if (typeof arg === "object") {
Expand Down Expand Up @@ -406,7 +406,7 @@
let httpsProvider: any;
try {
httpsProvider = require(httpsProviderV1Resolution);
} catch (e: any) {
} catch (e: unknown) {
httpsProvider = require(httpsProviderResolution);
}

Expand Down Expand Up @@ -644,7 +644,7 @@
let caughtErr;
try {
await func();
} catch (err: any) {
} catch (err: unknown) {
caughtErr = err;
}
if (caughtErr) {
Expand Down Expand Up @@ -757,10 +757,15 @@
let triggerModule;
try {
triggerModule = require(process.cwd());
} catch (err: any) {
if (err.code !== "ERR_REQUIRE_ESM") {
// Try to run diagnostics to see what could've gone wrong before rethrowing the error.
await moduleResolutionDetective(err);
} catch (err: unknown) {
if (typeof err === "object" && err !== null && "code" in err) {
const code = (err as { code: unknown }).code;
if (code !== "ERR_REQUIRE_ESM") {
// Try to run diagnostics to see what could've gone wrong before rethrowing the error.
await moduleResolutionDetective(err as unknown as Error);
throw err;
}
} else {
throw err;
}
const modulePath = require.resolve(process.cwd());
Comment thread
joehan marked this conversation as resolved.
Expand All @@ -780,7 +785,7 @@
let debug: FunctionsRuntimeBundle["debug"];
try {
debug = JSON.parse(message) as FunctionsRuntimeBundle["debug"];
} catch (e: any) {
} catch (e: unknown) {
new EmulatorLog("FATAL", "runtime-error", `Got unexpected message body: ${message}`).log();
await flushAndExit(1);
return;
Expand Down Expand Up @@ -819,11 +824,12 @@
await initializeRuntime();
try {
functionModule = await loadTriggers();
} catch (e: any) {
} catch (e: unknown) {
const message = e instanceof Error ? e.message : String(e);
new EmulatorLog(
"FATAL",
"runtime-status",
`Failed to initialize and load triggers. This shouldn't happen: ${e.message}`,
`Failed to initialize and load triggers. This shouldn't happen: ${message}`,
).log();
await flushAndExit(1);
}
Expand Down Expand Up @@ -889,9 +895,14 @@
case "http":
await runHTTPS(trigger, [req, res]);
}
} catch (err: any) {
new EmulatorLog("FATAL", "runtime-error", err.stack ? err.stack : err).log();
res.status(500).send(err.message);
} catch (err: unknown) {
const stack =
typeof err === "object" && err !== null && "stack" in err
? (err as { stack: string }).stack
: undefined;
const message = err instanceof Error ? err.message : String(err);
new EmulatorLog("FATAL", "runtime-error", stack ? stack : String(err)).log();
res.status(500).send(message);

Check warning

Code scanning / CodeQL

Information exposure through a stack trace Medium

This information exposed to the user depends on
stack trace information
.
This information exposed to the user depends on
stack trace information
.

Check warning

Code scanning / CodeQL

Exception text reinterpreted as HTML Medium

Exception text
is reinterpreted as HTML without escaping meta-characters.
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
}
});
app.listen(process.env.PORT, () => {
Expand Down
Loading
Loading