Show error if renderer is not found

This commit is contained in:
Matt Bierner 2021-06-16 14:24:50 -07:00
parent 79966bbfd2
commit 9488c96122
No known key found for this signature in database
GPG key ID: 099C331567E11888
2 changed files with 25 additions and 1 deletions

View file

@ -167,6 +167,10 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Disposable {
'notebook-markdown-min-height': `${this.options.previewNodePadding * 2}px`,
'notebook-cell-output-font-size': `${this.options.fontSize}px`,
'notebook-cell-markup-empty-content': nls.localize('notebook.emptyMarkdownPlaceholder', "Empty markdown cell, double click or press enter to edit."),
'notebook-cell-renderer-not-found-error': nls.localize({
key: 'notebook.error.rendererNotFound',
comment: ['$0 is a placeholder for the mime type']
}, "No renderer found for '$0' a"),
};
}
@ -249,6 +253,10 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Disposable {
overflow-x: scroll;
}
#container .no-renderer-error {
color: var(--vscode-editorError-foreground);
}
body {
padding: 0px;
height: 100%;

View file

@ -904,7 +904,23 @@ async function webviewPreloads(style: PreloadStyles, options: PreloadOptions, re
.filter(renderer => renderer.data.mimeTypes.includes(info.mime) && !renderer.data.extends);
if (!renderers.length) {
throw new Error('Could not find renderer');
const errorContainer = document.createElement('div');
const error = document.createElement('div');
error.className = 'no-renderer-error';
const errorText = (document.documentElement.style.getPropertyValue('--notebook-cell-renderer-not-found-error') || '').replace('$0', info.mime);
error.innerText = errorText;
const cellText = document.createElement('div');
cellText.innerText = info.text();
errorContainer.appendChild(error);
errorContainer.appendChild(cellText);
element.innerText = '';
element.appendChild(errorContainer);
return;
}
await Promise.all(renderers.map(x => x.load()));