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
8 changes: 7 additions & 1 deletion web/packages/shared/utils/assertUnreachable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,11 @@
*/

export function assertUnreachable(x: never): never {
throw new Error(`Unhandled case: ${x}`);
throw new UnhandledCaseError(x);
}

export class UnhandledCaseError extends Error {
constructor(public unhandledCase: unknown) {
super(`Unhandled case: ${unhandledCase}`);
}
}
16 changes: 14 additions & 2 deletions web/packages/teleterm/src/ui/components/CatchError/CatchError.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@

import React from 'react';

import { UnhandledCaseError } from 'shared/utils/assertUnreachable';

import { FailedApp } from 'teleterm/ui/components/App';
import Logger from 'teleterm/logger';

export class CatchError extends React.Component {
logger = new Logger('components/CatchError');
logger = new Logger('CatchError');

static getDerivedStateFromError(error) {
return { error };
Expand All @@ -33,7 +35,17 @@ export class CatchError extends React.Component {
};

componentDidCatch(err) {
this.logger.error('render', err);
if (err instanceof UnhandledCaseError) {
try {
// Log this message only to console to avoid storing it on disk. unhandledCase might be an
// object which holds sensitive data.
console.error('Unhandled case', JSON.stringify(err.unhandledCase));
} catch (error) {
console.error('Cannot stringify unhandled case', error);
}
}

this.logger.error('Caught', err.stack || err);
}

render() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/

import { ClusterOrResourceUri, routing } from 'teleterm/ui/uri';
import { assertUnreachable } from 'teleterm/ui/utils';

import { Document, isDocumentTshNodeWithServerId } from './types';

Expand Down Expand Up @@ -57,6 +56,7 @@ export function getResourceUri(
case 'doc.blank':
return undefined;
default:
assertUnreachable(document);
document satisfies never;
return undefined;
}
}