8000 feat: display meaningful error msg when cannot determine target (#6594) · firebase/firebase-tools@3ed5803 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3ed5803

Browse files
authored
feat: display meaningful error msg when cannot determine target (#6594)
* feat: display meaningful error msg when incorrect target is provided * feat: add entry to changelog * fix: format * feat: code improvements after review * fix: update import statement * fix: lint * fix: prettier
1 parent 2a44ed5 commit 3ed5803

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
- Improved detection of 'dataconnect.yaml' when not in project root.
33
- GitHub Action fixes for web frameworks (#6883)
44
- Fixes issue where PubSub message `publishTime` is set to 1970-01-01T00:00:00 (#7441)
5+
- Display meaningful error message when cannot determine target. (#6594)

src/frameworks/angular/utils.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { JsonObject } from "@angular-devkit/core";
12
import type { Target } from "@angular-devkit/architect";
23
import type { ProjectDefinition } from "@angular-devkit/core/src/workspace";
34
import type { WorkspaceNodeModulesArchitectHost } from "@angular-devkit/architect/node";
@@ -177,10 +178,9 @@ export async function getContext(dir: string, targetOrConfiguration?: string) {
177178
if (apps.length === 1) project = apps[0];
178179
}
179180

180-
if (!project)
181-
throw new FirebaseError(
182-
"Unable to determine the application to deploy, specify a target via the FIREBASE_FRAMEWORKS_BUILD_TARGET environment variable",
183-
);
181+
if (!project) {
182+
throwCannotDetermineTarget();
183+
}
184184

185185
const workspaceProject = workspace.projects.get(project);
186186
if (!workspaceProject) throw new FirebaseError(`No project ${project} found.`);
@@ -378,7 +378,8 @@ export async function getContext(dir: string, targetOrConfiguration?: string) {
378378
if (!buildOrBrowserTarget) {
379379
throw new FirebaseError(`No build target on ${project}`);
380380
}
381-
const browserTargetOptions = await architectHost.getOptionsForTarget(buildOrBrowserTarget);
381+
382+
const browserTargetOptions = await tryToGetOptionsForTarget(architectHost, buildOrBrowserTarget);
382383
if (!browserTargetOptions) {
383384
const targetString = targetStringFromTarget(buildOrBrowserTarget);
384385
throw new FirebaseError(`Couldn't find options for ${targetString}.`);
@@ -387,7 +388,8 @@ export async function getContext(dir: string, targetOrConfiguration?: string) {
387388
const baseHref = browserTargetOptions.baseHref || "/";
388389
assertIsString(baseHref);
389390

390-
const buildTargetOptions = buildTarget && (await architectHost.getOptionsForTarget(buildTarget));
391+
const buildTargetOptions =
392+
buildTarget && (await tryToGetOptionsForTarget(architectHost, buildTarget));
391393
const ssr = buildTarget ? !!buildTargetOptions?.ssr : !!serverTarget;
392394

393395
return {
@@ -561,3 +563,20 @@ export function getAngularVersion(cwd: string): string | undefined {
561563

562564
return angularVersionSemver.toString();
563565
}
566+
567+
/**
568+
* Try to get options for target, throw an error when expected target doesn't exist in the configuration.
569+
*/
570+
export async function tryToGetOptionsForTarget(
571+
architectHost: WorkspaceNodeModulesArchitectHost,
572+
target: Target,
573+
): Promise<JsonObject | null> {
574+
return await architectHost.getOptionsForTarget(target).catch(throwCannotDetermineTarget);
575+
}
576+
577+
function throwCannotDetermineTarget(error?: Error): never {
578+
throw new FirebaseError(
579+
`Unable to determine the application to deploy, specify a target via the FIREBASE_FRAMEWORKS_BUILD_TARGET environment variable.`,
580+
{ original: error },
581+
);
582+
}

0 commit comments

Comments
 (0)
0