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

Improve error message when given invalid hosting configuration. #5533

Merged
merged 4 commits into from
Feb 18, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- Allow configuration of the Cloud Function generated for full-stack web frameworks (#5504)
- Improve error message during deploy when given invalid hosting rewrite rule (#5533)
9 changes: 8 additions & 1 deletion src/deploy/hosting/convertConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,14 @@ export async function convertConfig(

// This line makes sure this function breaks if there is ever added a new
// kind of rewrite and we haven't yet handled it.
assertExhaustive(rewrite);
try {
assertExhaustive(rewrite);
} catch (e: any) {
throw new FirebaseError(
"Invalid hosting rewrite config in firebase.json. " +
"A rewrite config must specify 'destination', 'function', 'dynamicLinks', or 'run'"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the only list of situations where this can happen? If so, then this should bef ine

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes!

);
}
});

if (config.rewrites) {
Expand Down
2 changes: 1 addition & 1 deletion src/functional.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const zipIn =
/** Used with type guards to guarantee that all cases have been covered. */
export function assertExhaustive(val: never): never {
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
throw new Error(`Never has a value (${val}). This should be impossible`);
throw new Error(`Never has a value (${val}).`);
}

/**
Expand Down