Skip to content

Commit

Permalink
added exception sink facet to codemirror
Browse files Browse the repository at this point in the history
  • Loading branch information
imolorhe committed Dec 2, 2023
1 parent 9bfc270 commit ae9c0cb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/altair-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"prebuild": "rimraf dist",
"start": "nest start",
"start:debug": "nest start --debug --watch",
"start:dev": "nest start --watch",
"start:dev": "rm dist && nest start --watch",
"start:prod": "node dist/main",
"migrate:e2e": "dotenv -e .env.e2e -- prisma migrate deploy --schema ../altair-db/prisma/schema.prisma",
"test": "jest",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
} from '@codemirror/language';

import { tags as t } from '@lezer/highlight';
import { InternalEditorError } from '../../utils/errors';

@Component({
selector: 'app-codemirror',
Expand Down Expand Up @@ -177,6 +178,9 @@ export class CodemirrorComponent
this.zone.run(() => this.focusChanged(vu.view.hasFocus));
}
});
const exceptionSink = EditorView.exceptionSink.of((exception) => {
throw new InternalEditorError(exception);
});
const baseTheme = EditorView.theme({
'&.cm-editor': {
cursor: 'text',
Expand Down Expand Up @@ -398,6 +402,7 @@ export class CodemirrorComponent

return [
updateListener,
exceptionSink,
Prec.highest(extraExtensions),
!this.bare ? [...baseExtensions] : [],

Expand Down
13 changes: 13 additions & 0 deletions packages/altair-app/src/app/modules/altair/utils/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,16 @@ export const catchUselessObservableError = catchError((err) => {
debug.error(err);
return EMPTY;
});

class BaseError extends Error {
constructor(message: string, options?: { cause: unknown }) {
super(message, options);
this.name = this.constructor.name;
}
}

export class InternalEditorError extends BaseError {
constructor(cause: unknown) {
super('Internal editor error occurred', { cause });
}
}

0 comments on commit ae9c0cb

Please sign in to comment.