您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

errors.ts 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * MARTINS.js Free Edition
  3. * GPU-accelerated Augmented Reality for the web
  4. * Copyright (C) 2022 Alexandre Martins <alemartf(at)gmail.com>
  5. * https://github.com/alemart/martins-js
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Affero General Public License version 3
  9. * as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. *
  19. * errors.ts
  20. * Error classes
  21. */
  22. type ErrorCause = Error | null;
  23. /**
  24. * Generic error class
  25. */
  26. abstract class MartinsError extends Error
  27. {
  28. /**
  29. * Constructor
  30. * @param message error message
  31. * @param cause optional error cause
  32. */
  33. constructor(message = '', public readonly cause: ErrorCause = null)
  34. {
  35. super(`${message}\n${cause ? cause.toString() : ''}`);
  36. }
  37. /**
  38. * Error name
  39. */
  40. public get name(): string
  41. {
  42. return this.constructor.name;
  43. }
  44. }
  45. /**
  46. * A method has received one or more illegal arguments
  47. */
  48. export class IllegalArgumentError extends MartinsError
  49. {
  50. }
  51. /**
  52. * The method arguments are valid, but the method can't be called due to the
  53. * current state of the object
  54. */
  55. export class IllegalOperationError extends MartinsError
  56. {
  57. }
  58. /**
  59. * The requested operation is not supported
  60. */
  61. export class NotSupportedError extends MartinsError
  62. {
  63. }
  64. /**
  65. * Access denied
  66. */
  67. export class AccessDeniedError extends MartinsError
  68. {
  69. }
  70. /**
  71. * Assertion error
  72. */
  73. export class AssertionError extends MartinsError
  74. {
  75. }
  76. /**
  77. * Tracking error
  78. */
  79. export class TrackingError extends MartinsError
  80. {
  81. }
  82. /**
  83. * Detection error
  84. */
  85. export class DetectionError extends MartinsError
  86. {
  87. }
  88. /**
  89. * Training error
  90. */
  91. export class TrainingError extends MartinsError
  92. {
  93. }