Skip to content

Commit 0e1c259

Browse files
aalejjoehan
andauthored
Add validation to check if backendId exists when --only flag is used (#10170)
* add validation to check if backendId exists when --only flag is used * add changelog entry * add tests * typo --------- Co-authored-by: Joe Hanley <joehanley@google.com>
1 parent 54673bd commit 0e1c259

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Add validation to check if backendId exists in `firebase.json` when `--only` flag is used. (#10161)

src/deploy/apphosting/prepare.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,18 @@ describe("apphosting", () => {
479479
},
480480
]);
481481
});
482+
483+
it("throws error when no backend ID in firebase.json matches the one provided in --only flag", () => {
484+
expect(() =>
485+
getBackendConfigs({
486+
...BASE_OPTS,
487+
only: "apphosting:baz",
488+
config: new Config({
489+
apphosting: apphostingConfig,
490+
}),
491+
}),
492+
).to.throw("App Hosting backend IDs baz not detected in firebase.json");
493+
});
482494
});
483495

484496
describe("injectEnvVarsFromApphostingConfig", () => {

src/deploy/apphosting/prepare.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,17 @@ export function getBackendConfigs(options: Options): AppHostingMultiple {
309309
if (backendIds.length === 0) {
310310
return [];
311311
}
312-
return backendConfigs.filter((cfg) => backendIds.includes(cfg.backendId));
312+
313+
const filteredConfigs = backendConfigs.filter((cfg) => backendIds.includes(cfg.backendId));
314+
const foundIds = filteredConfigs.map((cfg) => cfg.backendId);
315+
const missingIds = backendIds.filter((id) => !foundIds.includes(id));
316+
if (missingIds.length > 0) {
317+
throw new FirebaseError(
318+
`App Hosting backend IDs ${missingIds.join(",")} not detected in firebase.json`,
319+
);
320+
}
321+
322+
return filteredConfigs;
313323
}
314324

315325
/**

0 commit comments

Comments
 (0)