Skip to content

Commit 620fcd2

Browse files
committed
Avoid crashing entirely given unexpected Send message update types
This is important for future extension, since it's required to be able to add more steps without breaking old UIs.
1 parent 352fb38 commit 620fcd2

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/model/send/send-store.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as _ from 'lodash';
2-
import { action, autorun, flow, observable, runInAction } from 'mobx';
2+
import { action, flow, observable, runInAction } from 'mobx';
33
import * as uuid from 'uuid/v4';
44
import {
55
MOCKTTP_PARAM_REF,
@@ -12,7 +12,7 @@ import {
1212
import { logError } from '../../errors';
1313
import { getObservableDeferred, lazyObservablePromise } from '../../util/observable';
1414
import { persist, hydrate } from '../../util/mobx-persist/persist';
15-
import { ErrorLike, UnreachableCheck } from '../../util/error';
15+
import { ErrorLike, unreachableWarning } from '../../util/error';
1616
import { rawHeadersToHeaders } from '../../util/headers';
1717
import { trackEvent } from '../../metrics';
1818

@@ -307,7 +307,7 @@ const trackResponseEvents = flow(function * (
307307
throw new Error('Unknown response error');
308308
}
309309
default:
310-
throw new UnreachableCheck(messageType);
310+
unreachableWarning(messageType);
311311
}
312312
}
313313
});

src/util/error.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,10 @@ export class UnreachableCheck extends Error {
3737
// Sometimes useful when you need an expression (when you can't use a 'throws' statement):
3838
export const unreachableCheck = (value: never, getValue: (v: any) => any = (x => x)): never => {
3939
throw new UnreachableCheck(value, getValue);
40+
}
41+
42+
// For cases where we want to type-safe check for unreachability, but not actually break (e.g.
43+
// APIs that might return new values in future).
44+
export const unreachableWarning = (value: never, getValue: (v: any) => any = (x => x)) => {
45+
console.warn(`Unhandled case value: ${getValue(value)}`);
4046
}

0 commit comments

Comments
 (0)