Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
22 changes: 16 additions & 6 deletions src/appdistribution/distribution.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import * as fs from "fs-extra";
import { upload, Distribution, awaitTestResults, DistributionFileType } from "./distribution";
import { AppDistributionClient } from "./client";
import { UploadReleaseResult, ReleaseTest } from "./types";
import { UploadReleaseResult, ReleaseTest, Release, TestDevice } from "./types";
import * as utils from "../utils";

describe("appdistribution/distribution", () => {
Expand Down Expand Up @@ -68,7 +68,11 @@
mockClient.uploadRelease.resolves("operations/123");
mockClient.pollUploadStatus.resolves({
result: UploadReleaseResult.RELEASE_CREATED,
release: { displayVersion: "1.0", buildVersion: "1", name: "test-rel" } as unknown as any,
release: {
displayVersion: "1.0",
buildVersion: "1",
name: "test-rel",
} as unknown as Release,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: no need unknown here

});

const res = await upload(
Expand All @@ -94,34 +98,40 @@

describe("awaitTestResults", () => {
it("should succeed when all tests pass on first poll", async () => {
const releaseTests: ReleaseTest[] = [{ name: "tests/1", deviceExecutions: [] } as any];
const releaseTests: ReleaseTest[] = [{ name: "tests/1", deviceExecutions: [] }];
mockClient.getReleaseTest.resolves({
name: "tests/1",
deviceExecutions: [{ state: "PASSED", device: { model: "Pixel" } as unknown as any }],
deviceExecutions: [
{ state: "PASSED", device: { model: "Pixel" } as unknown as TestDevice },
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: no need unknown here

],
} as unknown as ReleaseTest);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: no need unknown here


const setTimeoutStub = sinon.stub(global, "setTimeout").callsFake((fn) => fn() as any);

Check warning on line 109 in src/appdistribution/distribution.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type

Check warning on line 109 in src/appdistribution/distribution.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe return of an `any` typed value

await awaitTestResults(releaseTests, mockClient as any);

Check warning on line 111 in src/appdistribution/distribution.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type

Check warning on line 111 in src/appdistribution/distribution.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe argument of type `any` assigned to a parameter of type `AppDistributionClient`

expect(logSuccessStub).to.have.been.calledWithMatch(/Automated test\(s\) passed/);
setTimeoutStub.restore();
});

it("should fail immediately when a test execution fails", async () => {
const releaseTests: ReleaseTest[] = [{ name: "tests/1", deviceExecutions: [] } as any];
const releaseTests: ReleaseTest[] = [{ name: "tests/1", deviceExecutions: [] }];
mockClient.getReleaseTest.resolves({

Check warning on line 119 in src/appdistribution/distribution.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe argument of type `any` assigned to a parameter of type `ReleaseTest | undefined`
name: "tests/1",
deviceExecutions: [
{ state: "FAILED", failedReason: "Crash", device: { model: "Pixel" } as any },
{
state: "FAILED",
failedReason: "Crash",
device: { model: "Pixel" } as unknown as TestDevice,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unknown

},
],
} as any);

Check warning on line 128 in src/appdistribution/distribution.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type

const setTimeoutStub = sinon.stub(global, "setTimeout").callsFake((fn) => fn() as any);

Check warning on line 130 in src/appdistribution/distribution.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type

Check warning on line 130 in src/appdistribution/distribution.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe return of an `any` typed value

let caughtError: any;

Check warning on line 132 in src/appdistribution/distribution.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
try {
await awaitTestResults(releaseTests, mockClient as any);

Check warning on line 134 in src/appdistribution/distribution.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe argument of type `any` assigned to a parameter of type `AppDistributionClient`
} catch (err) {
caughtError = err;
}
Expand Down
22 changes: 15 additions & 7 deletions src/apphosting/secrets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,21 @@ export async function loadSecret(project: string | undefined, name: string): Pro
}
try {
return await gcsm.accessSecretVersion(projectId, secretId, version);
} catch (err: any) {
if (err?.original?.code === 403 || err?.original?.context?.response?.statusCode === 403) {
utils.logLabeledError(
"apphosting",
`Permission denied to access secret ${secretId}. Use ` +
`${clc.bold("firebase apphosting:secrets:grantaccess")} to get permissions.`,
);
} catch (err: unknown) {
if (err instanceof FirebaseError) {
const original = err.original;
if (typeof original === "object" && original !== null) {
if (
(original as any).code === 403 ||
(original as any).context?.response?.statusCode === 403
) {
utils.logLabeledError(
"apphosting",
`Permission denied to access secret ${secretId}. Use ` +
`${clc.bold("firebase apphosting:secrets:grantaccess")} to get permissions.`,
);
}
}
}
throw err;
}
Expand Down
7 changes: 4 additions & 3 deletions src/emulator/adminSdkConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { firebaseApiOrigin } from "../api";
import * as apiv2 from "../apiv2";
import { configstore } from "../configstore";
import { FirebaseError } from "../error";
import { getError } from "../error";
import { logger } from "../logger";
import { Constants } from "./constants";

Expand Down Expand Up @@ -43,7 +44,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 +72,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: getError(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
15 changes: 9 additions & 6 deletions src/emulator/commandUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { requireAuth } from "../requireAuth";
import { requireConfig } from "../requireConfig";
import { Emulators, ALL_SERVICE_EMULATORS } from "./types";
import { FirebaseError } from "../error";
import { getError } from "../error";
import { EmulatorRegistry } from "./registry";
import { getProjectId } from "../projectUtils";
import { confirm } from "../prompt";
Expand Down Expand Up @@ -172,8 +173,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 +334,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 +513,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: getError(err),
}),
);
}

Expand Down
20 changes: 9 additions & 11 deletions src/emulator/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
import { Constants, FIND_AVAILBLE_PORT_BY_DEFAULT } from "./constants";
import { EmulatableBackend, FunctionsEmulator } from "./functionsEmulator";
import { FirebaseError } from "../error";
import { getErrMsg, getError } from "../error";
import { getProjectId, getAliases, needProjectNumber } from "../projectUtils";
import * as commandUtils from "./commandUtils";
import { EmulatorHub } from "./hub";
Expand Down Expand Up @@ -174,11 +175,11 @@ export function shouldStart(options: Options, name: Emulators): boolean {
try {
normalizeAndValidate(options.config.src.functions);
return true;
} catch (err: any) {
} catch (err: unknown) {
EmulatorLogger.forEmulator(Emulators.FUNCTIONS).logLabeled(
"ERROR",
"functions",
`Failed to start Functions emulator: ${err.message}`,
`Failed to start Functions emulator: ${getErrMsg(err)}`,
);
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,8 @@ 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) {
databaseLogger.log("DEBUG", `Failed to retrieve default database instance: ${getErrMsg(e)}`);
}

const rc = dbRulesConfig.normalizeRulesConfig(
Expand Down Expand Up @@ -1117,7 +1115,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 +1159,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: getError(e),
});
}

Expand Down
21 changes: 12 additions & 9 deletions src/emulator/dataconnectEmulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
} from "./downloadableEmulators";
import { EmulatorInfo, EmulatorInstance, Emulators, ListenSpec } from "./types";
import { FirebaseError } from "../error";
import { getErrMsg, getErrStatus } from "../error";
import { EmulatorLogger } from "./emulatorLogger";
import { BuildResult, mainSchemaYaml, requiresVector } from "../dataconnect/types";
import { listenSpecsToString } from "./portUtils";
Expand Down Expand Up @@ -95,8 +96,8 @@ export class DataConnectEmulator implements EmulatorInstance {
);
}
}
} catch (err: any) {
this.logger.log("DEBUG", `'fdc build' failed with error: ${err.message}`);
} catch (err: unknown) {
this.logger.log("DEBUG", `'fdc build' failed with error: ${getErrMsg(err)}`);
}
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): ${getErrMsg(err)}`,
);
await new Promise((resolve) => setTimeout(resolve, 2000));
}
Expand Down Expand Up @@ -413,9 +414,11 @@ 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) {
const status = getErrStatus(err);
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
Loading
Loading