Skip to content

Commit 5b6cf4a

Browse files
committed
Add more logging and typechecking
1 parent d390dd8 commit 5b6cf4a

File tree

4 files changed

+37
-8
lines changed

4 files changed

+37
-8
lines changed

packages/app/src/app/overmind/effects/live/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,16 @@ class Live {
143143
operation: this.operationToElixir(operation.toJSON()),
144144
revision,
145145
}).catch(error => {
146+
logBreadcrumb({
147+
type: 'ot',
148+
message: `ERROR ${JSON.stringify({
149+
moduleShortid,
150+
revision,
151+
operation,
152+
message: error.message,
153+
})}`,
154+
});
155+
146156
captureException(error);
147157
this.onOperationError({
148158
...error.module_state[moduleShortid],

packages/app/src/app/overmind/namespaces/live/actions.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { filter, fork, pipe } from 'overmind';
1010

1111
import * as internalActions from './internalActions';
1212
import * as liveMessage from './liveMessageOperators';
13+
import { IModuleStateModule } from './types';
1314

1415
export const internal = internalActions;
1516

@@ -27,14 +28,14 @@ export const signInToRoom: AsyncAction<{
2728

2829
export const onOperationError: Action<{
2930
moduleShortid: string;
30-
code: string;
31-
revision: number;
32-
saved_code: string;
33-
}> = ({ state, effects }, { moduleShortid, revision, code, saved_code }) => {
31+
} & IModuleStateModule> = (
32+
{ state, effects },
33+
{ moduleShortid, revision, code, saved_code }
34+
) => {
3435
if (!state.editor.currentSandbox) {
3536
return;
3637
}
37-
effects.live.resetClient(moduleShortid, revision);
38+
effects.live.resetClient(moduleShortid, revision || 0);
3839
const module = state.editor.currentSandbox.modules.find(
3940
moduleItem => moduleItem.shortid === moduleShortid
4041
);

packages/app/src/app/overmind/namespaces/live/internalActions.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Action, AsyncAction } from 'app/overmind';
77
import { json } from 'overmind';
88

99
import { getSavedCode } from '../../utils/sandbox';
10+
import { IModuleStateModule } from './types';
1011

1112
export const clearUserSelections: Action<string | null> = (
1213
{ state, effects },
@@ -89,7 +90,11 @@ export const initialize: AsyncAction<string, Sandbox | null> = async (
8990
return null;
9091
};
9192

92-
export const initializeModuleState: Action<any> = (
93+
interface IModuleState {
94+
[moduleId: string]: IModuleStateModule;
95+
}
96+
97+
export const initializeModuleState: Action<IModuleState> = (
9398
{ state, actions, effects },
9499
moduleState
95100
) => {
@@ -117,8 +122,15 @@ export const initializeModuleState: Action<any> = (
117122
moduleInfo.saved_code !== module.savedCode;
118123

119124
if (moduleChanged) {
120-
module.savedCode = moduleInfo.saved_code;
121-
module.code = moduleInfo.code;
125+
if (
126+
moduleInfo.saved_code === null &&
127+
typeof moduleInfo.saved_code === 'string'
128+
) {
129+
module.savedCode = moduleInfo.saved_code;
130+
}
131+
if (typeof moduleInfo.code === 'string') {
132+
module.code = moduleInfo.code;
133+
}
122134

123135
if (savedCodeChanged) {
124136
effects.vscode.sandboxFsSync.writeFile(
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export interface IModuleStateModule {
2+
synced?: boolean;
3+
revision?: number;
4+
code?: string;
5+
saved_code?: string | null;
6+
}

0 commit comments

Comments
 (0)