Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions packages/super-editor/src/editors/v1/core/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3808,9 +3808,7 @@ export class Editor extends EventEmitter<EditorEventMap> {
getUpdatedDocs = false,
fieldsHighlightColor = null,
compression,
}: ExportDocxParams = {}): Promise<
Blob | Buffer | Record<string, string | null> | string | ConvertedXmlPart | undefined
> {
}: ExportDocxParams = {}): Promise<Blob | Buffer | Record<string, string | null> | string | ConvertedXmlPart> {
try {
const exportHostEditor = resolveMainBodyEditor(this);
commitLiveStorySessionRuntimes(exportHostEditor);
Expand Down Expand Up @@ -4081,6 +4079,7 @@ export class Editor extends EventEmitter<EditorEventMap> {
const err = error instanceof Error ? error : new Error(String(error));
this.emit('exception', { error: err, editor: this });
console.error(err);
throw err;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { describe, expect, it, vi } from 'vitest';
import { Editor } from '@core/Editor.js';

const SAMPLE_JSON = {
type: 'doc',
attrs: { attrs: null },
content: [
{
type: 'paragraph',
content: [{ type: 'text', text: 'Export errors should reach the caller' }],
},
],
};

describe('Editor.exportDocx() error handling', () => {
it('emits an exception event and rejects when export fails', async () => {
const editor = await Editor.open(undefined, { json: SAMPLE_JSON });
const exportError = new Error('export failed');
const exceptionListener = vi.fn();
const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});

editor.on('exception', exceptionListener);
vi.spyOn(editor.converter, 'exportToDocx').mockRejectedValue(exportError);

try {
await expect(editor.exportDocx({ exportXmlOnly: true })).rejects.toBe(exportError);

expect(exceptionListener).toHaveBeenCalledTimes(1);
expect(exceptionListener).toHaveBeenCalledWith({ error: exportError, editor });
expect(consoleErrorSpy).toHaveBeenCalledWith(exportError);
} finally {
consoleErrorSpy.mockRestore();
editor.destroy();
}
});
});
Loading