errors.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. const errors = {
  2. /* Header error messages */
  3. INVALID_LOC: "Invalid LOC header (bad signature)",
  4. INVALID_CEN: "Invalid CEN header (bad signature)",
  5. INVALID_END: "Invalid END header (bad signature)",
  6. /* Descriptor */
  7. DESCRIPTOR_NOT_EXIST: "No descriptor present",
  8. DESCRIPTOR_UNKNOWN: "Unknown descriptor format",
  9. DESCRIPTOR_FAULTY: "Descriptor data is malformed",
  10. /* ZipEntry error messages*/
  11. NO_DATA: "Nothing to decompress",
  12. BAD_CRC: "CRC32 checksum failed {0}",
  13. FILE_IN_THE_WAY: "There is a file in the way: {0}",
  14. UNKNOWN_METHOD: "Invalid/unsupported compression method",
  15. /* Inflater error messages */
  16. AVAIL_DATA: "inflate::Available inflate data did not terminate",
  17. INVALID_DISTANCE: "inflate::Invalid literal/length or distance code in fixed or dynamic block",
  18. TO_MANY_CODES: "inflate::Dynamic block code description: too many length or distance codes",
  19. INVALID_REPEAT_LEN: "inflate::Dynamic block code description: repeat more than specified lengths",
  20. INVALID_REPEAT_FIRST: "inflate::Dynamic block code description: repeat lengths with no first length",
  21. INCOMPLETE_CODES: "inflate::Dynamic block code description: code lengths codes incomplete",
  22. INVALID_DYN_DISTANCE: "inflate::Dynamic block code description: invalid distance code lengths",
  23. INVALID_CODES_LEN: "inflate::Dynamic block code description: invalid literal/length code lengths",
  24. INVALID_STORE_BLOCK: "inflate::Stored block length did not match one's complement",
  25. INVALID_BLOCK_TYPE: "inflate::Invalid block type (type == 3)",
  26. /* ADM-ZIP error messages */
  27. CANT_EXTRACT_FILE: "Could not extract the file",
  28. CANT_OVERRIDE: "Target file already exists",
  29. DISK_ENTRY_TOO_LARGE: "Number of disk entries is too large",
  30. NO_ZIP: "No zip file was loaded",
  31. NO_ENTRY: "Entry doesn't exist",
  32. DIRECTORY_CONTENT_ERROR: "A directory cannot have content",
  33. FILE_NOT_FOUND: 'File not found: "{0}"',
  34. NOT_IMPLEMENTED: "Not implemented",
  35. INVALID_FILENAME: "Invalid filename",
  36. INVALID_FORMAT: "Invalid or unsupported zip format. No END header found",
  37. INVALID_PASS_PARAM: "Incompatible password parameter",
  38. WRONG_PASSWORD: "Wrong Password",
  39. /* ADM-ZIP */
  40. COMMENT_TOO_LONG: "Comment is too long", // Comment can be max 65535 bytes long (NOTE: some non-US characters may take more space)
  41. EXTRA_FIELD_PARSE_ERROR: "Extra field parsing error"
  42. };
  43. // template
  44. function E(message) {
  45. return function (...args) {
  46. if (args.length) { // Allow {0} .. {9} arguments in error message, based on argument number
  47. message = message.replace(/\{(\d)\}/g, (_, n) => args[n] || '');
  48. }
  49. return new Error('ADM-ZIP: ' + message);
  50. };
  51. }
  52. // Init errors with template
  53. for (const msg of Object.keys(errors)) {
  54. exports[msg] = E(errors[msg]);
  55. }