Skip to content

Commit 850506c

Browse files
committed
Use <pre> tag for error messages in showErrorMessage dialog
...to preserve line breaks and use a monospace font so e.g. pre-commit errors are readable. Partially addresses #1407.
1 parent 5b5678b commit 850506c

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/notifications.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Dialog, Notification, showErrorMessage } from '@jupyterlab/apputils';
22
import { TranslationBundle } from '@jupyterlab/translation';
3+
import React from 'react'; // Add this import
34

45
/**
56
* Build notification options to display in a dialog the detailed error.
@@ -18,9 +19,26 @@ export function showError(
1819
{
1920
label: trans.__('Show'),
2021
callback: () => {
21-
showErrorMessage(trans.__('Error'), error, [
22-
Dialog.warnButton({ label: trans.__('Dismiss') })
23-
]);
22+
showErrorMessage(
23+
trans.__('Error'),
24+
{
25+
message: React.createElement(
26+
React.Fragment,
27+
null,
28+
React.createElement(
29+
// Render error in a <pre> element to preserve line breaks and
30+
// use a monospace font so e.g. pre-commit errors are readable.
31+
// Ref: https://github.com/jupyterlab/jupyterlab-git/issues/1407
32+
'pre',
33+
{ style: { whiteSpace: 'pre-wrap', fontSize: '7pt' } },
34+
error.message || error.stack || String(error)
35+
)
36+
)
37+
},
38+
[
39+
Dialog.warnButton({ label: trans.__('Dismiss') })
40+
]
41+
);
2442
},
2543
displayType: 'warn'
2644
} as Notification.IAction

0 commit comments

Comments
 (0)