Open History to see the last commit
1import * as Schema from "effect/Schema";
2
3// No GT import: preview workers load this, and their errors cross `postMessage` as a code.
4// `zipErrorMessages.ts` holds the translatable text for each code.
5const CODES = [
6 "file-too-large",
7 "archive-too-many-entries",
8 "archive-path-too-long",
9 "archive-expanded-too-large",
10 "zip-unreadable",
11 "zip64-unsupported",
12 "zip64-damaged",
13 "zip-directory-damaged",
14] as const;
15
16export type ZipErrorCode = (typeof CODES)[number];
17
18const ENGLISH: Record<ZipErrorCode, string> = {
19 "file-too-large": "Preview limited to files under 50 MB.",
20 "archive-too-many-entries": "This archive contains more than 2,048 entries.",
21 "archive-path-too-long": "An archive path is too long to preview.",
22 "archive-expanded-too-large":
23 "The expanded archive exceeds the preview size or compression ratio limit.",
24 "zip-unreadable": "This is not a readable ZIP archive.",
25 "zip64-unsupported": "Unsupported ZIP64 directory.",
26 "zip64-damaged": "This ZIP64 directory is too large or damaged.",
27 "zip-directory-damaged": "This ZIP directory is damaged.",
28};
29
30/** A ZIP the preview limits reject; `message` stays English for logs. */
31export class ZipError extends Schema.TaggedError<ZipError>()("ZipError", {
32 code: Schema.Literals(CODES),
33}) {
34 override get message(): string {
35 return ENGLISH[this.code];
36 }
37}
38
39export const isZipError = Schema.is(ZipError);