Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug where backends:list and backends:get command fails when no backends exists. #6600

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
32 changes: 12 additions & 20 deletions src/commands/frameworks-backends-get.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
import * as gcp from "../gcp/frameworks";
import { Command } from "../command";
import { Options } from "../options";
import { needProjectId } from "../projectUtils";
import * as gcp from "../gcp/frameworks";
import { FirebaseError } from "../error";
import { logger } from "../logger";
import { ensureApiEnabled } from "../gcp/frameworks";
import { logWarning } from "../utils";

const Table = require("cli-table");

Check warning on line 10 in src/commands/frameworks-backends-get.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value

Check warning on line 10 in src/commands/frameworks-backends-get.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Require statement not part of import statement
const COLUMN_LENGTH = 20;
const TABLE_HEAD = [
"Backend Id",
"Repository Name",
"Location",
"URL",
"Created Date",
"Updated Date",
];
const TABLE_HEAD = ["Backend Id", "Repository", "Location", "URL", "Created Date", "Updated Date"];
export const command = new Command("backends:get <backendId>")
.description("Get backend details of a Firebase project")
.option("-l, --location <location>", "App Backend location", "-")
Expand All @@ -25,36 +19,34 @@
const location = options.location as string;

let backendsList: gcp.Backend[] = [];
const table = new Table({

Check warning on line 22 in src/commands/frameworks-backends-get.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value

Check warning on line 22 in src/commands/frameworks-backends-get.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe construction of an any type value
head: TABLE_HEAD,
style: { head: ["green"] },
});
table.colWidths = COLUMN_LENGTH;

Check warning on line 26 in src/commands/frameworks-backends-get.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .colWidths on an `any` value
try {
if (location !== "-") {
const backendInRegion = await gcp.getBackend(projectId, location, backendId);
backendsList.push(backendInRegion);
populateTable(backendInRegion, table);
} else {
const allBackend = await gcp.listBackends(projectId, location);
backendsList = allBackend.backends.filter((bkd) => bkd.name.split("/").pop() === backendId);
const resp = await gcp.listBackends(projectId, "-");
const allBackends = resp.backends || [];
backendsList = allBackends.filter((bkd) => bkd.name.split("/").pop() === backendId);
backendsList.forEach((bkd) => populateTable(bkd, table));
}

if (backendsList.length !== 0) {
logger.info(table.toString());
} else {
logger.info();
logger.info(`There are no backends with id: ${backendId}`);
}
} catch (err: any) {

Check warning on line 38 in src/commands/frameworks-backends-get.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
throw new FirebaseError(
`Failed to get backend: ${backendId}. Please check the parameters you have provided.`,
{ original: err }

Check warning on line 41 in src/commands/frameworks-backends-get.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
);
}

return backendsList;
if (backendsList.length === 0) {
logWarning(`Found no backend with id: ${backendId}`);
return;
}
logger.info(table.toString());

Check warning on line 48 in src/commands/frameworks-backends-get.ts

View workflow job for this annotation

GitHub Actions / lint (20)

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

Check warning on line 48 in src/commands/frameworks-backends-get.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .toString on an `any` value

Check warning on line 48 in src/commands/frameworks-backends-get.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe call of an `any` typed value
return backendsList[0];
});

function populateTable(backend: gcp.Backend, table: any) {
Expand Down
7 changes: 1 addition & 6 deletions src/commands/frameworks-backends-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { needProjectId } from "../projectUtils";
import * as gcp from "../gcp/frameworks";
import { FirebaseError } from "../error";
import { logger } from "../logger";
import { bold } from "colorette";
import { ensureApiEnabled } from "../gcp/frameworks";

const Table = require("cli-table");
Expand All @@ -25,12 +24,8 @@ export const command = new Command("backends:list")
const backendsList: gcp.Backend[] = [];
try {
const backendsPerRegion = await gcp.listBackends(projectId, location);
backendsList.push(...backendsPerRegion.backends);
backendsList.push(...(backendsPerRegion.backends || []));
populateTable(backendsList, table);

logger.info();
logger.info(`Backends for project ${bold(projectId)}`);
logger.info();
logger.info(table.toString());
} catch (err: any) {
throw new FirebaseError(
Expand Down
Loading