Skip to content

Commit 814a699

Browse files
committed
feat: validation errors on import COMPAS-8867
1 parent a1682c2 commit 814a699

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

packages/compass-import-export/src/components/import-toast.tsx

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
Body,
44
Button,
55
css,
6+
Link,
67
openToast,
78
ToastBody,
89
} from '@mongodb-js/compass-components';
@@ -227,19 +228,21 @@ export function showFailedToast(
227228
err: Error | undefined,
228229
showErrorDetails?: () => void
229230
) {
230-
console.log({ err, showErrorDetails });
231231
openToast(importToastId, {
232232
title: 'Failed to import with the following error:',
233-
description: err?.message,
234-
variant: 'warning',
235-
actionElement: showErrorDetails && (err as MongoServerError).errInfo && (
236-
<Button
237-
size="xsmall"
238-
onClick={showErrorDetails}
239-
data-testid="insert-document-error-details-button"
240-
>
241-
VIEW ERROR DETAILS
242-
</Button>
233+
description: (
234+
<>
235+
{err?.message}&nbsp;
236+
{showErrorDetails && (
237+
<Link
238+
onClick={showErrorDetails}
239+
data-testid="insert-document-error-details-button"
240+
>
241+
View error details
242+
</Link>
243+
)}
244+
</>
243245
),
246+
variant: 'warning',
244247
});
245248
}

packages/compass-import-export/src/modules/import.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -389,11 +389,14 @@ export const startImport = (): ImportThunkAction<Promise<void>> => {
389389
debug('Error while importing:', err.stack);
390390

391391
progressCallback.flush();
392-
showFailedToast(err, () =>
393-
dispatch({ type: ERROR_DETAILS_OPENED, errorDetails: err.errInfo })
394-
);
395-
396-
dispatch(onFailed(err));
392+
const errInfo =
393+
err?.writeErrors?.length && err?.writeErrors[0]?.err?.errInfo;
394+
const showErrorDetails: () => void | undefined =
395+
errInfo &&
396+
(() => dispatch({ type: ERROR_DETAILS_OPENED, errorDetails: errInfo }));
397+
showFailedToast(err as Error, showErrorDetails);
398+
399+
dispatch(onFailed(err as Error));
397400
return;
398401
} finally {
399402
errorLogWriteStream?.close();

0 commit comments

Comments
 (0)