Skip to content

Commit

Permalink
Fix bug where backends:list and backends:get command fails when no ba…
Browse files Browse the repository at this point in the history
…ckends exists.
  • Loading branch information
taeold committed Dec 8, 2023
1 parent 36c99a6 commit fb40e82
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 26 deletions.
34 changes: 13 additions & 21 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 { logBullet, logWarning } from "../utils";

Check failure on line 8 in src/commands/frameworks-backends-get.ts

View workflow job for this annotation

GitHub Actions / unit (18)

'logBullet' is defined but never used

Check failure on line 8 in src/commands/frameworks-backends-get.ts

View workflow job for this annotation

GitHub Actions / lint (20)

'logBullet' is defined but never used

Check failure on line 8 in src/commands/frameworks-backends-get.ts

View workflow job for this annotation

GitHub Actions / unit (18)

'logBullet' is defined but never used

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 @@ -36,25 +30,23 @@ export const command = new Command("backends:get <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 }
{ children: 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: 2 additions & 5 deletions src/commands/frameworks-backends-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { FirebaseError } from "../error";
import { logger } from "../logger";
import { bold } from "colorette";

Check failure on line 7 in src/commands/frameworks-backends-list.ts

View workflow job for this annotation

GitHub Actions / unit (18)

'bold' is defined but never used

Check failure on line 7 in src/commands/frameworks-backends-list.ts

View workflow job for this annotation

GitHub Actions / lint (20)

'bold' is defined but never used

Check failure on line 7 in src/commands/frameworks-backends-list.ts

View workflow job for this annotation

GitHub Actions / unit (18)

'bold' is defined but never used
import { ensureApiEnabled } from "../gcp/frameworks";
import { logBullet } from "../utils";

Check failure on line 9 in src/commands/frameworks-backends-list.ts

View workflow job for this annotation

GitHub Actions / unit (18)

'logBullet' is defined but never used

Check failure on line 9 in src/commands/frameworks-backends-list.ts

View workflow job for this annotation

GitHub Actions / lint (20)

'logBullet' is defined but never used

Check failure on line 9 in src/commands/frameworks-backends-list.ts

View workflow job for this annotation

GitHub Actions / unit (18)

'logBullet' is defined but never used

const Table = require("cli-table");
const COLUMN_LENGTH = 20;
Expand All @@ -25,12 +26,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

0 comments on commit fb40e82

Please sign in to comment.