Skip to content
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
3 changes: 2 additions & 1 deletion src/providers/https.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import * as _ from 'lodash';
import { apps } from '../apps';
import { HttpsFunction, optionsToTrigger, Runnable } from '../cloud-functions';
import { DeploymentOptions } from '../function-configuration';
import { assertNever } from '../utilities/assertions';

export interface Request extends express.Request {
rawBody: Buffer;
Expand Down Expand Up @@ -231,7 +232,7 @@ export class HttpsError extends Error {
return 500;
// This should never happen as long as the type system is doing its job.
default:
throw new Error('Invalid error code: ' + this.code);
assertNever(this.code);
}
}

Expand Down
16 changes: 16 additions & 0 deletions src/utilities/assertions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* @file Provides common assertion helpers which can be used to improve
* strictness of both type checking and runtime.
*/

/**
* Checks that the given value is of type `never` — the type that’s left after
* all other cases have been removed.
*
* @param x A value of type `never`.
*/
export function assertNever(x: never): never {
throw new Error(
`Unhandled discriminated union member: ${JSON.stringify(x)}.`
);
}