mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(post card): clarify full error copying
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { formatErrorForDisplay } from '../error-utils';
|
||||
import { formatErrorForDisplay, serializeErrorForClipboard } from '../error-utils';
|
||||
|
||||
describe('error utils', () => {
|
||||
it('returns plain string errors unchanged', () => {
|
||||
@@ -29,4 +29,55 @@ describe('error utils', () => {
|
||||
}),
|
||||
).toBe('publish failed: provider: plebpubsub; reason: timeout');
|
||||
});
|
||||
|
||||
it('formats nested Error details without dropping the nested message', () => {
|
||||
expect(
|
||||
formatErrorForDisplay({
|
||||
details: {
|
||||
reason: new Error('provider timeout'),
|
||||
},
|
||||
message: 'publish failed',
|
||||
}),
|
||||
).toBe('publish failed: reason: provider timeout');
|
||||
});
|
||||
|
||||
it('formats cyclic errors without recursing forever', () => {
|
||||
const error = Object.assign(new Error('publish failed'), {
|
||||
details: {
|
||||
elapsedMs: BigInt(5000),
|
||||
},
|
||||
});
|
||||
Object.assign(error.details, { self: error.details });
|
||||
|
||||
expect(formatErrorForDisplay(error)).toBe('publish failed: elapsedMs: 5000; self: [Circular]');
|
||||
});
|
||||
|
||||
it('serializes cyclic errors as valid JSON for copying', () => {
|
||||
const cause = new Error('provider timeout');
|
||||
const error = Object.assign(new Error('publish failed'), {
|
||||
attempts: [{ elapsedMs: BigInt(5000), provider: 'pubsub', reason: cause }],
|
||||
});
|
||||
Object.assign(error, { self: error });
|
||||
|
||||
expect(JSON.parse(serializeErrorForClipboard(error))).toMatchObject({
|
||||
attempts: [
|
||||
{
|
||||
elapsedMs: '5000',
|
||||
provider: 'pubsub',
|
||||
reason: {
|
||||
message: 'provider timeout',
|
||||
name: 'Error',
|
||||
},
|
||||
},
|
||||
],
|
||||
message: 'publish failed',
|
||||
name: 'Error',
|
||||
self: '[Circular]',
|
||||
});
|
||||
});
|
||||
|
||||
it('keeps string errors unchanged and empty objects as JSON', () => {
|
||||
expect(serializeErrorForClipboard('plain failure')).toBe('plain failure');
|
||||
expect(serializeErrorForClipboard({})).toBe('{}');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user