Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 7 additions & 3 deletions firebase-vscode/src/data-connect/ad-hoc-mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export function registerAdHoc(
const queryName = `${ast.name.value.charAt(0).toLowerCase()}${ast.name.value.slice(1)}s`;

return `
# This is a file for you to write an un-named queries.
# This is a file for you to write an un-named query.
# Only one un-named query is allowed per file.
query {
${queryName}${buildRecursiveObjectQuery(ast)!}
Expand Down Expand Up @@ -158,7 +158,9 @@ query {
}
const schema = buildClientSchema(introspect.data);
const dataType = schema.getType(`${ast.name.value}_Data`);
if (!isInputObjectType(dataType)) return;
if (!isInputObjectType(dataType)) {
return;
}

const adhocMutation = print(
await makeAdHocMutation(
Expand Down Expand Up @@ -206,7 +208,9 @@ query {
for (const field of fields) {
const type = getNamedType(field.type);
const defaultValue = getDefaultScalarValue(type.name);
if (!defaultValue) continue;
if (!defaultValue) {
continue;
}

argumentFields.push({
kind: Kind.OBJECT_FIELD,
Expand Down
2 changes: 1 addition & 1 deletion firebase-vscode/src/data-connect/explorer-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export class ExplorerTreeDataProvider
return { name: f.name, baseType: OPERATION_TYPE.mutation };
});
}
const field = this._field(element)
const field = this._field(element);
if (field) {
const unwrapped = this._baseType(field);
const type = this._unref(unwrapped);
Expand Down
41 changes: 21 additions & 20 deletions src/appdistribution/client.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { ReadStream } from "fs";

import { appDistributionOrigin } from "../api";
import { Client, ClientResponse } from "../apiv2";
import { FirebaseError } from "../error";
import * as operationPoller from "../operation-poller";
import * as utils from "../utils";
import * as operationPoller from "../operation-poller";
import { Distribution } from "./distribution";
import { FirebaseError, getErrMsg } from "../error";
import { Client, ClientResponse } from "../apiv2";
import { appDistributionOrigin } from "../api";

import {
AabInfo,
BatchRemoveTestersResponse,
Expand Down Expand Up @@ -83,8 +84,8 @@

try {
await this.appDistroV1Client.patch(`/${releaseName}`, data, { queryParams });
} catch (err: any) {
throw new FirebaseError(`failed to update release notes with ${err?.message}`);
} catch (err: unknown) {
throw new FirebaseError(`failed to update release notes with ${getErrMsg(err)}`);
}

utils.logSuccess("added release notes successfully");
Expand All @@ -109,15 +110,15 @@

try {
await this.appDistroV1Client.post(`/${releaseName}:distribute`, data);
} catch (err: any) {

Check warning on line 113 in src/appdistribution/client.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
let errorMessage = err.message;

Check warning on line 114 in src/appdistribution/client.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value

Check warning on line 114 in src/appdistribution/client.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .message on an `any` value
const errorStatus = err?.context?.body?.error?.status;

Check warning on line 115 in src/appdistribution/client.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value

Check warning on line 115 in src/appdistribution/client.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .context on an `any` value
if (errorStatus === "FAILED_PRECONDITION") {
errorMessage = "invalid testers";
} else if (errorStatus === "INVALID_ARGUMENT") {
errorMessage = "invalid groups";
}
throw new FirebaseError(`failed to distribute to testers/groups: ${errorMessage}`, {

Check warning on line 121 in src/appdistribution/client.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Invalid type "any" of template literal expression
exit: 1,
});
}
Expand Down Expand Up @@ -148,7 +149,7 @@
queryParams,
});
} catch (err) {
throw new FirebaseError(`Client request failed to list testers ${err}`);

Check warning on line 152 in src/appdistribution/client.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Invalid type "unknown" of template literal expression
}

for (const t of apiResponse.body.testers) {
Expand All @@ -172,8 +173,8 @@
path: `${projectName}/testers:batchAdd`,
body: { emails: emails },
});
} catch (err: any) {
throw new FirebaseError(`Failed to add testers ${err}`);
} catch (err: unknown) {
throw new FirebaseError(`Failed to add testers ${getErrMsg(err)}`);
}

utils.logSuccess(`Testers created successfully`);
Expand All @@ -190,8 +191,8 @@
path: `${projectName}/testers:batchRemove`,
body: { emails: emails },
});
} catch (err: any) {
throw new FirebaseError(`Failed to remove testers ${err}`);
} catch (err: unknown) {
throw new FirebaseError(`Failed to remove testers ${getErrMsg(err)}`);
}
return apiResponse.body;
}
Expand All @@ -214,7 +215,7 @@
listGroupsResponse.groups.push(...(apiResponse.body.groups || []));
pageToken = apiResponse.body.nextPageToken;
} catch (err) {
throw new FirebaseError(`Client failed to list groups ${err}`);

Check warning on line 218 in src/appdistribution/client.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Invalid type "unknown" of template literal expression
}
} while (pageToken);
return listGroupsResponse;
Expand All @@ -229,8 +230,8 @@
alias === undefined ? `${projectName}/groups` : `${projectName}/groups?groupId=${alias}`,
body: { displayName: displayName },
});
} catch (err: any) {
throw new FirebaseError(`Failed to create group ${err}`);
} catch (err: unknown) {
throw new FirebaseError(`Failed to create group ${getErrMsg(err)}`);
}
return apiResponse.body;
}
Expand All @@ -241,8 +242,8 @@
method: "DELETE",
path: groupName,
});
} catch (err: any) {
throw new FirebaseError(`Failed to delete group ${err}`);
} catch (err: unknown) {
throw new FirebaseError(`Failed to delete group ${getErrMsg(err)}`);
}

utils.logSuccess(`Group deleted successfully`);
Expand All @@ -255,8 +256,8 @@
path: `${groupName}:batchJoin`,
body: { emails: emails },
});
} catch (err: any) {
throw new FirebaseError(`Failed to add testers to group ${err}`);
} catch (err: unknown) {
throw new FirebaseError(`Failed to add testers to group ${getErrMsg(err)}`);
}

utils.logSuccess(`Testers added to group successfully`);
Expand All @@ -269,8 +270,8 @@
path: `${groupName}:batchLeave`,
body: { emails: emails },
});
} catch (err: any) {
throw new FirebaseError(`Failed to remove testers from group ${err}`);
} catch (err: unknown) {
throw new FirebaseError(`Failed to remove testers from group ${getErrMsg(err)}`);
}

utils.logSuccess(`Testers removed from group successfully`);
Expand All @@ -291,8 +292,8 @@
},
});
return response.body;
} catch (err: any) {
throw new FirebaseError(`Failed to create release test ${err}`);
} catch (err: unknown) {
throw new FirebaseError(`Failed to create release test ${getErrMsg(err)}`);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/appdistribution/distribution.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as fs from "fs-extra";
import { FirebaseError } from "../error";
import { FirebaseError, getErrMsg } from "../error";
import { logger } from "../logger";
import * as pathUtil from "path";

Expand Down Expand Up @@ -33,8 +33,8 @@ export class Distribution {
let stat;
try {
stat = fs.statSync(path);
} catch (err: any) {
logger.info(err);
} catch (err: unknown) {
logger.info(getErrMsg(err));
throw new FirebaseError(`File ${path} does not exist: verify that file points to a binary`);
}
if (!stat.isFile()) {
Expand Down
16 changes: 8 additions & 8 deletions src/apphosting/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import { Backend, BackendOutputOnlyFields, API_VERSION } from "../gcp/apphosting";
import { addServiceAccountToRoles } from "../gcp/resourceManager";
import * as iam from "../gcp/iam";
import { FirebaseError } from "../error";
import { FirebaseError, getErrStatus, getError } from "../error";
import { promptOnce } from "../prompt";
import { DEFAULT_LOCATION } from "./constants";
import { ensure } from "../ensureApiEnabled";
Expand Down Expand Up @@ -48,7 +48,7 @@
// SSL.
const maybeNodeError = err as { cause: { code: string }; code: string };
if (
/HANDSHAKE_FAILURE/.test(maybeNodeError?.cause?.code) ||

Check warning on line 51 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Use `String#includes()` method with a string instead
"EPROTO" === maybeNodeError?.code
) {
return false;
Expand Down Expand Up @@ -263,19 +263,19 @@
async function promptNewBackendId(
projectId: string,
location: string,
prompt: any,

Check warning on line 266 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
): Promise<string> {
while (true) {
const backendId = await promptOnce(prompt);
try {
await apphosting.getBackend(projectId, location, backendId);
} catch (err: any) {
if (err.status === 404) {
} catch (err: unknown) {
if (getErrStatus(err) === 404) {
return backendId;
}
throw new FirebaseError(
`Failed to check if backend with id ${backendId} already exists in ${location}`,
{ original: err },
{ original: getError(err) },
);
}
logWarning(`Backend with id ${backendId} already exists in ${location}`);
Expand Down Expand Up @@ -331,9 +331,9 @@
"Default service account used to run builds and deploys for Firebase App Hosting",
"Firebase App Hosting compute service account",
);
} catch (err: any) {
} catch (err: unknown) {
// 409 Already Exists errors can safely be ignored.
if (err.status !== 409) {
if (getErrStatus(err) !== 409) {
throw err;
}
}
Expand Down Expand Up @@ -422,9 +422,9 @@
): Promise<apphosting.Backend> {
try {
return await apphosting.getBackend(projectId, location, backendId);
} catch (err: any) {
} catch (err: unknown) {
throw new FirebaseError(`No backend named "${backendId}" found in ${location}.`, {
original: err,
original: getError(err),
});
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/apphosting/secrets/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FirebaseError } from "../../error";
import { FirebaseError, getErrStatus, getError } from "../../error";
import * as iam from "../../gcp/iam";
import * as gcsm from "../../gcp/secretManager";
import * as gcb from "../../gcp/cloudbuild";
Expand Down Expand Up @@ -100,21 +100,21 @@ export async function grantSecretAccess(
let existingBindings;
try {
existingBindings = (await gcsm.getIamPolicy({ projectId, name: secretName })).bindings || [];
} catch (err: any) {
} catch (err: unknown) {
throw new FirebaseError(
`Failed to get IAM bindings on secret: ${secretName}. Ensure you have the permissions to do so and try again.`,
{ original: err },
{ original: getError(err) },
);
}

try {
// TODO: Merge with existing bindings with the same role
const updatedBindings = existingBindings.concat(newBindings);
await gcsm.setIamPolicy({ projectId, name: secretName }, updatedBindings);
} catch (err: any) {
} catch (err: unknown) {
throw new FirebaseError(
`Failed to set IAM bindings ${JSON.stringify(newBindings)} on secret: ${secretName}. Ensure you have the permissions to do so and try again.`,
{ original: err },
{ original: getError(err) },
);
}

Expand All @@ -136,9 +136,9 @@ export async function upsertSecret(
let existing: gcsm.Secret;
try {
existing = await gcsm.getSecret(project, secret);
} catch (err: any) {
if (err.status !== 404) {
throw new FirebaseError("Unexpected error loading secret", { original: err });
} catch (err: unknown) {
if (getErrStatus(err) !== 404) {
throw new FirebaseError("Unexpected error loading secret", { original: getError(err) });
}
await gcsm.createSecret(project, secret, gcsm.labels("apphosting"), location);
return true;
Expand Down
6 changes: 3 additions & 3 deletions src/archiveDirectory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as path from "path";
import * as tar from "tar";
import * as tmp from "tmp";

import { FirebaseError } from "./error";
import { FirebaseError, getError } from "./error";
import { listFiles } from "./listFiles";
import { logger } from "./logger";
import { Readable, Writable } from "stream";
Expand Down Expand Up @@ -62,11 +62,11 @@ export async function archiveDirectory(
const archive = await makeArchive;
logger.debug(`Archived ${filesize(archive.size)} in ${sourceDirectory}.`);
return archive;
} catch (err: any) {
} catch (err: unknown) {
if (err instanceof FirebaseError) {
throw err;
}
throw new FirebaseError("Failed to create archive.", { original: err });
throw new FirebaseError("Failed to create archive.", { original: getError(err) });
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as url from "url";

import * as apiv2 from "./apiv2";
import { configstore } from "./configstore";
import { FirebaseError } from "./error";
import { FirebaseError, getErrMsg } from "./error";
import * as utils from "./utils";
import { logger } from "./logger";
import { promptOnce } from "./prompt";
Expand Down Expand Up @@ -318,7 +318,7 @@ async function getTokensFromAuthorizationCode(
headers: form.getHeaders(),
skipLog: { body: true, queryParams: true, resBody: true },
});
} catch (err: any) {
} catch (err: unknown) {
if (err instanceof Error) {
logger.debug("Token Fetch Error:", err.stack || "");
} else {
Expand Down Expand Up @@ -515,7 +515,7 @@ async function loginWithLocalhost<ResultType>(
const tokens = await getTokens(queryCode, callbackUrl);
respondHtml(req, res, 200, successHtml);
resolve(tokens);
} catch (err: any) {
} catch (err: unknown) {
const html = await readTemplate("loginFailure.html");
respondHtml(req, res, 400, html);
reject(err);
Expand Down Expand Up @@ -730,8 +730,8 @@ export async function getAccessToken(refreshToken: string, authScopes: string[])
} else {
try {
return refreshAuth();
} catch (err: any) {
logger.debug(`Unable to refresh token: ${err}`);
} catch (err: unknown) {
logger.debug(`Unable to refresh token: ${getErrMsg(err)}`);
}
throw new FirebaseError("Unable to getAccessToken");
}
Expand Down
14 changes: 7 additions & 7 deletions src/commands/appdistribution-distribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
UploadReleaseResult,
TestDevice,
} from "../appdistribution/types";
import { FirebaseError } from "../error";
import { FirebaseError, getErrMsg, getErrStatus } from "../error";
import { Distribution, DistributionFileType } from "../appdistribution/distribution";
import {
ensureFileExists,
Expand Down Expand Up @@ -96,8 +96,8 @@ export const command = new Command("appdistribution:distribute <release-binary-f
if (distribution.distributionFileType() === DistributionFileType.AAB) {
try {
aabInfo = await requests.getAabInfo(appName);
} catch (err: any) {
if (err.status === 404) {
} catch (err: unknown) {
if (getErrStatus(err) === 404) {
throw new FirebaseError(
`App Distribution could not find your app ${options.app}. ` +
`Make sure to onboard your app by pressing the "Get started" ` +
Expand All @@ -106,7 +106,7 @@ export const command = new Command("appdistribution:distribute <release-binary-f
{ exit: 1 },
);
}
throw new FirebaseError(`failed to determine AAB info. ${err.message}`, { exit: 1 });
throw new FirebaseError(`failed to determine AAB info. ${getErrMsg(err)}`, { exit: 1 });
}

if (
Expand Down Expand Up @@ -175,8 +175,8 @@ export const command = new Command("appdistribution:distribute <release-binary-f
`Download the release binary (link expires in 1 hour): ${release.binaryDownloadUri}`,
);
releaseName = uploadResponse.release.name;
} catch (err: any) {
if (err.status === 404) {
} catch (err: unknown) {
if (getErrStatus(err) === 404) {
throw new FirebaseError(
`App Distribution could not find your app ${options.app}. ` +
`Make sure to onboard your app by pressing the "Get started" ` +
Expand All @@ -185,7 +185,7 @@ export const command = new Command("appdistribution:distribute <release-binary-f
{ exit: 1 },
);
}
throw new FirebaseError(`Failed to upload release. ${err.message}`, { exit: 1 });
throw new FirebaseError(`Failed to upload release. ${getErrMsg(err)}`, { exit: 1 });
}

// If this is an app bundle and the certificate was originally blank fetch the updated
Expand Down
6 changes: 3 additions & 3 deletions src/commands/appdistribution-groups-delete.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Command } from "../command";
import * as utils from "../utils";
import { requireAuth } from "../requireAuth";
import { FirebaseError } from "../error";
import { FirebaseError, getErrMsg } from "../error";
import { AppDistributionClient } from "../appdistribution/client";
import { getProjectName } from "../appdistribution/options-parser-util";

Expand All @@ -15,8 +15,8 @@ export const command = new Command("appdistribution:groups:delete <alias>")
try {
utils.logBullet(`Deleting group from project`);
await appDistroClient.deleteGroup(`${projectName}/groups/${alias}`);
} catch (err: any) {
throw new FirebaseError(`Failed to delete group ${err}`);
} catch (err: unknown) {
throw new FirebaseError(`Failed to delete group ${getErrMsg(err)}`);
}
utils.logSuccess(`Group ${alias} has successfully been deleted`);
});
Loading
Loading