Errors.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /* eslint-disable no-proto
  2. */
  3. // TODO: This file was created by bulk-decaffeinate.
  4. // Fix any style issues and re-enable lint.
  5. import OError from '@overleaf/o-error'
  6. export function NotFoundError(message) {
  7. const error = new Error(message)
  8. error.name = 'NotFoundError'
  9. error.__proto__ = NotFoundError.prototype
  10. return error
  11. }
  12. NotFoundError.prototype.__proto__ = Error.prototype
  13. export function FilesOutOfSyncError(message) {
  14. const error = new Error(message)
  15. error.name = 'FilesOutOfSyncError'
  16. error.__proto__ = FilesOutOfSyncError.prototype
  17. return error
  18. }
  19. FilesOutOfSyncError.prototype.__proto__ = Error.prototype
  20. export function AlreadyCompilingError(message) {
  21. const error = new Error(message)
  22. error.name = 'AlreadyCompilingError'
  23. error.__proto__ = AlreadyCompilingError.prototype
  24. return error
  25. }
  26. AlreadyCompilingError.prototype.__proto__ = Error.prototype
  27. export class QueueLimitReachedError extends OError {}
  28. export class TimedOutError extends OError {}
  29. export class NoXrefTableError extends OError {}
  30. export class TooManyCompileRequestsError extends OError {}
  31. export class InvalidParameter extends OError {}
  32. export class MissingUpdatesError extends OError {}
  33. export class ConversionError extends OError {
  34. static USER_FACING_ERRORS = new Set([
  35. 1, // IO error
  36. 23, // Unsupported extension
  37. 24, // Citeproc error
  38. 25, // Other bibliography error
  39. 44, // Malformed XML error
  40. 63, // Generic error (e.g. malformed docx container)
  41. 64, // Parse error
  42. 91, // Macro loop
  43. 92, // UTF8 decoding error
  44. 94, // Unsupported char set
  45. 95, // Input not text
  46. 97, // Missing data file
  47. 98, // Missing metadata file
  48. 99, // Missing file
  49. ])
  50. isUserFacing
  51. stderr
  52. exitCode
  53. constructor(message, { type, stderr, exitCode }) {
  54. const isUserFacingError = ConversionError.USER_FACING_ERRORS.has(exitCode)
  55. super(message, { exitCode, type })
  56. this.isUserFacing = isUserFacingError
  57. this.stderr = stderr
  58. this.exitCode = exitCode
  59. }
  60. }
  61. export default {
  62. QueueLimitReachedError,
  63. TimedOutError,
  64. NotFoundError,
  65. FilesOutOfSyncError,
  66. AlreadyCompilingError,
  67. NoXrefTableError,
  68. TooManyCompileRequestsError,
  69. InvalidParameter,
  70. MissingUpdatesError,
  71. ConversionError,
  72. }