Skip to content

Commit d1a6abc

Browse files
committed
add logs for failed reverts
1 parent 8a9ede8 commit d1a6abc

File tree

3 files changed

+77
-10
lines changed

3 files changed

+77
-10
lines changed

src/notebooks/deepnote/deepnoteActivationService.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { injectable, inject } from 'inversify';
22
import { workspace } from 'vscode';
33
import { IExtensionSyncActivationService } from '../../platform/activation/types';
44
import { IExtensionContext } from '../../platform/common/types';
5+
import { ILogger } from '../../platform/logging/types';
56
import { IDeepnoteNotebookManager } from '../types';
67
import { DeepnoteNotebookSerializer } from './deepnoteSerializer';
78
import { DeepnoteExplorerView } from './deepnoteExplorerView';
@@ -25,7 +26,8 @@ export class DeepnoteActivationService implements IExtensionSyncActivationServic
2526
constructor(
2627
@inject(IExtensionContext) private extensionContext: IExtensionContext,
2728
@inject(IDeepnoteNotebookManager) private readonly notebookManager: IDeepnoteNotebookManager,
28-
@inject(IIntegrationManager) integrationManager: IIntegrationManager
29+
@inject(IIntegrationManager) integrationManager: IIntegrationManager,
30+
@inject(ILogger) private readonly logger: ILogger
2931
) {
3032
this.integrationManager = integrationManager;
3133
}
@@ -37,7 +39,7 @@ export class DeepnoteActivationService implements IExtensionSyncActivationServic
3739
public activate() {
3840
this.serializer = new DeepnoteNotebookSerializer(this.notebookManager);
3941
this.explorerView = new DeepnoteExplorerView(this.extensionContext, this.notebookManager);
40-
this.editProtection = new DeepnoteInputBlockEditProtection();
42+
this.editProtection = new DeepnoteInputBlockEditProtection(this.logger);
4143

4244
this.extensionContext.subscriptions.push(workspace.registerNotebookSerializer('deepnote', this.serializer));
4345
this.extensionContext.subscriptions.push(this.editProtection);

src/notebooks/deepnote/deepnoteActivationService.unit.test.ts

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ import { assert } from 'chai';
33
import { DeepnoteActivationService } from './deepnoteActivationService';
44
import { DeepnoteNotebookManager } from './deepnoteNotebookManager';
55
import { IExtensionContext } from '../../platform/common/types';
6+
import { ILogger } from '../../platform/logging/types';
67
import { IIntegrationManager } from './integrations/types';
78

89
suite('DeepnoteActivationService', () => {
910
let activationService: DeepnoteActivationService;
1011
let mockExtensionContext: IExtensionContext;
1112
let manager: DeepnoteNotebookManager;
1213
let mockIntegrationManager: IIntegrationManager;
14+
let mockLogger: ILogger;
1315

1416
setup(() => {
1517
mockExtensionContext = {
@@ -22,7 +24,20 @@ suite('DeepnoteActivationService', () => {
2224
return;
2325
}
2426
};
25-
activationService = new DeepnoteActivationService(mockExtensionContext, manager, mockIntegrationManager);
27+
mockLogger = {
28+
error: () => {},
29+
warn: () => {},
30+
info: () => {},
31+
debug: () => {},
32+
trace: () => {},
33+
ci: () => {}
34+
} as ILogger;
35+
activationService = new DeepnoteActivationService(
36+
mockExtensionContext,
37+
manager,
38+
mockIntegrationManager,
39+
mockLogger
40+
);
2641
});
2742

2843
suite('constructor', () => {
@@ -92,8 +107,24 @@ suite('DeepnoteActivationService', () => {
92107
return;
93108
}
94109
};
95-
const service1 = new DeepnoteActivationService(context1, manager1, mockIntegrationManager1);
96-
const service2 = new DeepnoteActivationService(context2, manager2, mockIntegrationManager2);
110+
const mockLogger1: ILogger = {
111+
error: () => {},
112+
warn: () => {},
113+
info: () => {},
114+
debug: () => {},
115+
trace: () => {},
116+
ci: () => {}
117+
} as ILogger;
118+
const mockLogger2: ILogger = {
119+
error: () => {},
120+
warn: () => {},
121+
info: () => {},
122+
debug: () => {},
123+
trace: () => {},
124+
ci: () => {}
125+
} as ILogger;
126+
const service1 = new DeepnoteActivationService(context1, manager1, mockIntegrationManager1, mockLogger1);
127+
const service2 = new DeepnoteActivationService(context2, manager2, mockIntegrationManager2, mockLogger2);
97128

98129
// Verify each service has its own context
99130
assert.strictEqual((service1 as any).extensionContext, context1);
@@ -128,8 +159,24 @@ suite('DeepnoteActivationService', () => {
128159
return;
129160
}
130161
};
131-
new DeepnoteActivationService(context1, manager1, mockIntegrationManager1);
132-
new DeepnoteActivationService(context2, manager2, mockIntegrationManager2);
162+
const mockLogger3: ILogger = {
163+
error: () => {},
164+
warn: () => {},
165+
info: () => {},
166+
debug: () => {},
167+
trace: () => {},
168+
ci: () => {}
169+
} as ILogger;
170+
const mockLogger4: ILogger = {
171+
error: () => {},
172+
warn: () => {},
173+
info: () => {},
174+
debug: () => {},
175+
trace: () => {},
176+
ci: () => {}
177+
} as ILogger;
178+
new DeepnoteActivationService(context1, manager1, mockIntegrationManager1, mockLogger3);
179+
new DeepnoteActivationService(context2, manager2, mockIntegrationManager2, mockLogger4);
133180

134181
assert.strictEqual(context1.subscriptions.length, 0);
135182
assert.strictEqual(context2.subscriptions.length, 1);

src/notebooks/deepnote/deepnoteInputBlockEditProtection.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { injectable, inject } from 'inversify';
12
import {
23
Disposable,
34
NotebookCell,
@@ -10,13 +11,15 @@ import {
1011
workspace,
1112
WorkspaceEdit
1213
} from 'vscode';
14+
import { ILogger } from '../../platform/logging/types';
1315
import { formatInputBlockCellContent } from './inputBlockContentFormatter';
1416

1517
/**
1618
* Protects readonly input blocks from being edited by reverting changes.
1719
* Also protects the language ID of all input blocks.
1820
* This is needed because VSCode doesn't support the `editable: false` metadata property.
1921
*/
22+
@injectable()
2023
export class DeepnoteInputBlockEditProtection implements Disposable {
2124
private readonly disposables: Disposable[] = [];
2225

@@ -55,7 +58,7 @@ export class DeepnoteInputBlockEditProtection implements Disposable {
5558
['button', 'python']
5659
]);
5760

58-
constructor() {
61+
constructor(@inject(ILogger) private readonly logger: ILogger) {
5962
// Listen for notebook document changes
6063
this.disposables.push(
6164
workspace.onDidChangeNotebookDocument((e) => {
@@ -125,7 +128,14 @@ export class DeepnoteInputBlockEditProtection implements Disposable {
125128
new Position(lastLine, cell.document.lineAt(lastLine).text.length)
126129
);
127130
edit.replace(cell.document.uri, fullRange, correctContent);
128-
await workspace.applyEdit(edit);
131+
const success = await workspace.applyEdit(edit);
132+
if (!success) {
133+
this.logger.error(
134+
`Failed to revert cell content for input block type '${blockType}' at cell index ${
135+
cell.index
136+
} in notebook ${cell.notebook.uri.toString()}`
137+
);
138+
}
129139
}
130140
}
131141

@@ -168,7 +178,15 @@ export class DeepnoteInputBlockEditProtection implements Disposable {
168178
workspaceEdit.set(uri, edits);
169179
}
170180

171-
await workspace.applyEdit(workspaceEdit);
181+
const success = await workspace.applyEdit(workspaceEdit);
182+
if (!success) {
183+
const cellInfo = cellsToFix
184+
.map(({ cell, blockType }) => `cell ${cell.index} (type: ${blockType})`)
185+
.join(', ');
186+
this.logger.error(
187+
`Failed to protect cell languages for ${cellsToFix.length} cell(s): ${cellInfo} in notebook(s)`
188+
);
189+
}
172190
}
173191

174192
dispose(): void {

0 commit comments

Comments
 (0)