Skip to content

Commit ef23437

Browse files
committed
Fix bug where backends:list and backends:get command fails when no backends exists.
1 parent 9842b8d commit ef23437

File tree

2 files changed

+13
-26
lines changed

2 files changed

+13
-26
lines changed

src/commands/frameworks-backends-get.ts

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
1+
import * as gcp from "../gcp/frameworks";
12
import { Command } from "../command";
23
import { Options } from "../options";
34
import { needProjectId } from "../projectUtils";
4-
import * as gcp from "../gcp/frameworks";
55
import { FirebaseError } from "../error";
66
import { logger } from "../logger";
77
import { ensureApiEnabled } from "../gcp/frameworks";
8+
import { logWarning } from "../utils";
89

910
const Table = require("cli-table");
1011
const COLUMN_LENGTH = 20;
11-
const TABLE_HEAD = [
12-
"Backend Id",
13-
"Repository Name",
14-
"Location",
15-
"URL",
16-
"Created Date",
17-
"Updated Date",
18-
];
12+
const TABLE_HEAD = ["Backend Id", "Repository", "Location", "URL", "Created Date", "Updated Date"];
1913
export const command = new Command("backends:get <backendId>")
2014
.description("Get backend details of a Firebase project")
2115
.option("-l, --location <location>", "App Backend location", "-")
@@ -36,25 +30,23 @@ export const command = new Command("backends:get <backendId>")
3630
backendsList.push(backendInRegion);
3731
populateTable(backendInRegion, table);
3832
} else {
39-
const allBackend = await gcp.listBackends(projectId, location);
40-
backendsList = allBackend.backends.filter((bkd) => bkd.name.split("/").pop() === backendId);
33+
const resp = await gcp.listBackends(projectId, "-");
34+
const allBackends = resp.backends || [];
35+
backendsList = allBackends.filter((bkd) => bkd.name.split("/").pop() === backendId);
4136
backendsList.forEach((bkd) => populateTable(bkd, table));
4237
}
43-
44-
if (backendsList.length !== 0) {
45-
logger.info(table.toString());
46-
} else {
47-
logger.info();
48-
logger.info(`There are no backends with id: ${backendId}`);
49-
}
5038
} catch (err: any) {
5139
throw new FirebaseError(
5240
`Failed to get backend: ${backendId}. Please check the parameters you have provided.`,
5341
{ original: err }
5442
);
5543
}
56-
57-
return backendsList;
44+
if (backendsList.length === 0) {
45+
logWarning(`Found no backend with id: ${backendId}`);
46+
return;
47+
}
48+
logger.info(table.toString());
49+
return backendsList[0];
5850
});
5951

6052
function populateTable(backend: gcp.Backend, table: any) {

src/commands/frameworks-backends-list.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { needProjectId } from "../projectUtils";
44
import * as gcp from "../gcp/frameworks";
55
import { FirebaseError } from "../error";
66
import { logger } from "../logger";
7-
import { bold } from "colorette";
87
import { ensureApiEnabled } from "../gcp/frameworks";
98

109
const Table = require("cli-table");
@@ -25,12 +24,8 @@ export const command = new Command("backends:list")
2524
const backendsList: gcp.Backend[] = [];
2625
try {
2726
const backendsPerRegion = await gcp.listBackends(projectId, location);
28-
backendsList.push(...backendsPerRegion.backends);
27+
backendsList.push(...(backendsPerRegion.backends || []));
2928
populateTable(backendsList, table);
30-
31-
logger.info();
32-
logger.info(`Backends for project ${bold(projectId)}`);
33-
logger.info();
3429
logger.info(table.toString());
3530
} catch (err: any) {
3631
throw new FirebaseError(

0 commit comments

Comments
 (0)