Skip to content

Commit

Permalink
Improve error message when given invalid hosting configuration. (#5533)
Browse files Browse the repository at this point in the history
Given invalid hosting configuration, Firebase CLI fails in an unhelpful way.

e.g. 
```
{
  "hosting": {
    "public": "public",
    "rewrites": [
      {
        // missing "destination", "function", or "run"
        "source": "**"
      }
    ]
  }
}
```

**Before**:
```
$ firebase deploy --only hosting
...
Error: An unexpected error has occurred.

$ firebase deploy --only hosting --debug
...
Error: Never has a value ([object Object]). This should be impossible
```

**After**
```
$ firebase deploy --only hosting
...
Error: Invalid hosting rewrite config in firebase.json. A rewrite config must specify 'destination', 'function', 'dynamicLinks', or 'run'
```

Fixes https://groups.google.com/a/google.com/g/firebase-discuss/c/VoQ0XkNnZFs
  • Loading branch information
taeold authored Feb 18, 2023
1 parent d6826ee commit 05f4f50
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
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'"
);
}
});

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

0 comments on commit 05f4f50

Please sign in to comment.