MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / exportErrorMessage

Function exportErrorMessage

web/src/lib/workspaces/exportError.ts:32–86  ·  view source on GitHub ↗
(err: unknown)

Source from the content-addressed store, hash-verified

30}
31
32export function exportErrorMessage(err: unknown): string {
33 const e = (err ?? {}) as { code?: unknown; message?: unknown; details?: unknown };
34 const message = typeof e.message === 'string' && e.message.trim() !== '' ? e.message : '';
35 if (typeof e.code !== 'string') return GENERIC;
36 if (e.code !== 'export_too_large') return message || GENERIC;
37
38 const d = (e.details && typeof e.details === 'object' ? e.details : {}) as Record<string, unknown>;
39
40 if (d.part === 'manifest' && num(d.limit_bytes) && num(d.size_reached)) {
41 const limit = formatBytes(d.limit_bytes);
42 const reached = formatBytes(d.size_reached);
43 // size_reached is the manifest's full size here, not a spool stop point.
44 const size = reached === limit ? 'it is just over that' : `it is ${reached}`;
45 return (
46 `This workspace's list of attachments is larger than this server's limit of ${limit} (${size}). ` +
47 `Leaving out version history does not help. ` +
48 `The CLI command pad workspace export --json exports the workspace without attachment blobs; ` +
49 `otherwise the server operator can raise PAD_EXPORT_METADATA_MAX_BYTES.`
50 );
51 }
52
53 if (
54 (d.part === undefined || d.part === 'export') &&
55 num(d.limit_bytes) &&
56 num(d.size_reached) &&
57 typeof d.include_versions === 'boolean'
58 ) {
59 const limit = formatBytes(d.limit_bytes);
60 const reached = formatBytes(d.size_reached);
61 // The server stops spooling just past the limit, so the two often
62 // round to the same figure.
63 const stopped = reached === limit ? 'it stopped just past that' : `it stopped at ${reached}`;
64 if (d.include_versions) {
65 return (
66 `This export is larger than this server's limit of ${limit} (${stopped}). ` +
67 `Tick "Leave out version history" and try again; that usually fits. ` +
68 `Otherwise the server operator can raise PAD_EXPORT_METADATA_MAX_BYTES.`
69 );
70 }
71 return (
72 `This export is larger than this server's limit of ${limit} even without version history (${stopped}). ` +
73 `The server operator can raise PAD_EXPORT_METADATA_MAX_BYTES.`
74 );
75 }
76
77 if (num(d.entries) && num(d.limit_entries)) {
78 return (
79 `This workspace has too many attachments for a bundle this server can import. ` +
80 `Leaving out version history does not help. ` +
81 `The CLI command pad workspace export --json exports the workspace without attachment blobs.`
82 );
83 }
84
85 return message || GENERIC;
86}

Callers 1

Calls 2

numFunction · 0.70
formatBytesFunction · 0.70

Tested by

no test coverage detected