diff --git a/extensions/ipynb/src/serializer.ts b/extensions/ipynb/src/serializer.ts index 8c880c051a6..b11a3733759 100644 --- a/extensions/ipynb/src/serializer.ts +++ b/extensions/ipynb/src/serializer.ts @@ -21,29 +21,22 @@ export class NotebookSerializer implements vscode.NotebookSerializer { } catch { } - let json: Partial; - try { - json = contents ? (JSON.parse(contents) as Partial) : {}; + let json = contents ? (JSON.parse(contents) as Partial) : {}; - if (json.__webview_backup) { - const backupId = json.__webview_backup; - const uri = this.context.globalStorageUri; - const folder = uri.with({ path: this.context.globalStorageUri.path.replace('vscode.ipynb', 'ms-toolsai.jupyter') }); - const fileHash = fnv.fast1a32hex(backupId) as string; - const fileName = `${fileHash}.ipynb`; - const file = vscode.Uri.joinPath(folder, fileName); - const data = await vscode.workspace.fs.readFile(file); - json = data ? JSON.parse(data.toString()) : {}; + if (json.__webview_backup) { + const backupId = json.__webview_backup; + const uri = this.context.globalStorageUri; + const folder = uri.with({ path: this.context.globalStorageUri.path.replace('vscode.ipynb', 'ms-toolsai.jupyter') }); + const fileHash = fnv.fast1a32hex(backupId) as string; + const fileName = `${fileHash}.ipynb`; + const file = vscode.Uri.joinPath(folder, fileName); + const data = await vscode.workspace.fs.readFile(file); + json = data ? JSON.parse(data.toString()) : {}; - if (json.contents && typeof json.contents === 'string') { - contents = json.contents; - json = JSON.parse(contents) as Partial; - } + if (json.contents && typeof json.contents === 'string') { + contents = json.contents; + json = JSON.parse(contents) as Partial; } - } catch (e) { - console.log(contents); - console.log(e); - throw e; } // Then compute indent from the contents