errors.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.LibzipError = exports.ERR_DIR_CLOSED = exports.EOPNOTSUPP = exports.ENOTEMPTY = exports.EROFS = exports.EEXIST = exports.EISDIR = exports.ENOTDIR = exports.ENOENT = exports.EBADF = exports.EINVAL = exports.ENOSYS = exports.EBUSY = void 0;
  4. function makeError(code, message) {
  5. return Object.assign(new Error(`${code}: ${message}`), { code });
  6. }
  7. function EBUSY(message) {
  8. return makeError(`EBUSY`, message);
  9. }
  10. exports.EBUSY = EBUSY;
  11. function ENOSYS(message, reason) {
  12. return makeError(`ENOSYS`, `${message}, ${reason}`);
  13. }
  14. exports.ENOSYS = ENOSYS;
  15. function EINVAL(reason) {
  16. return makeError(`EINVAL`, `invalid argument, ${reason}`);
  17. }
  18. exports.EINVAL = EINVAL;
  19. function EBADF(reason) {
  20. return makeError(`EBADF`, `bad file descriptor, ${reason}`);
  21. }
  22. exports.EBADF = EBADF;
  23. function ENOENT(reason) {
  24. return makeError(`ENOENT`, `no such file or directory, ${reason}`);
  25. }
  26. exports.ENOENT = ENOENT;
  27. function ENOTDIR(reason) {
  28. return makeError(`ENOTDIR`, `not a directory, ${reason}`);
  29. }
  30. exports.ENOTDIR = ENOTDIR;
  31. function EISDIR(reason) {
  32. return makeError(`EISDIR`, `illegal operation on a directory, ${reason}`);
  33. }
  34. exports.EISDIR = EISDIR;
  35. function EEXIST(reason) {
  36. return makeError(`EEXIST`, `file already exists, ${reason}`);
  37. }
  38. exports.EEXIST = EEXIST;
  39. function EROFS(reason) {
  40. return makeError(`EROFS`, `read-only filesystem, ${reason}`);
  41. }
  42. exports.EROFS = EROFS;
  43. function ENOTEMPTY(reason) {
  44. return makeError(`ENOTEMPTY`, `directory not empty, ${reason}`);
  45. }
  46. exports.ENOTEMPTY = ENOTEMPTY;
  47. function EOPNOTSUPP(reason) {
  48. return makeError(`EOPNOTSUPP`, `operation not supported, ${reason}`);
  49. }
  50. exports.EOPNOTSUPP = EOPNOTSUPP;
  51. // ------------------------------------------------------------------------
  52. function ERR_DIR_CLOSED() {
  53. return makeError(`ERR_DIR_CLOSED`, `Directory handle was closed`);
  54. }
  55. exports.ERR_DIR_CLOSED = ERR_DIR_CLOSED;
  56. // ------------------------------------------------------------------------
  57. class LibzipError extends Error {
  58. constructor(message, code) {
  59. super(message);
  60. this.name = `Libzip Error`;
  61. this.code = code;
  62. }
  63. }
  64. exports.LibzipError = LibzipError;