index.d.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. declare namespace PluginError {
  2. interface Constructor {
  3. /**
  4. * @param plugin Plugin name
  5. * @param error Base error
  6. * @param options Error options
  7. */
  8. new <E extends Error>(plugin: string, error: E, options?: Options): PluginError<E>;
  9. /**
  10. * @param plugin Plugin name
  11. * @param error Base error or error message
  12. * @param options Error options
  13. */
  14. new <E extends Error = Error>(plugin: string, error: E | string, options: Options): PluginError<E | {[K in keyof E]: undefined}>;
  15. /**
  16. * @param plugin Plugin name
  17. * @param error Base error, error message, or options with message
  18. */
  19. new <E extends Error = Error>(plugin: string, error: E | string | (Options & {message: string})): PluginError<E | {[K in keyof E]: undefined}>;
  20. /**
  21. * @param options Options with plugin name and message
  22. */
  23. new(options: Options & {plugin: string, message: string}): PluginError;
  24. }
  25. interface Options {
  26. /**
  27. * Error name
  28. */
  29. name?: string;
  30. /**
  31. * Error message
  32. */
  33. message?: any;
  34. /**
  35. * File name where the error occurred
  36. */
  37. fileName?: string;
  38. /**
  39. * Line number where the error occurred
  40. */
  41. lineNumber?: number;
  42. /**
  43. * Error properties will be included in err.toString(). Can be omitted by
  44. * setting this to false.
  45. *
  46. * Default: `true`
  47. */
  48. showProperties?: boolean;
  49. /**
  50. * By default the stack will not be shown. Set this to true if you think the
  51. * stack is important for your error.
  52. *
  53. * Default: `false`
  54. */
  55. showStack?: boolean;
  56. /**
  57. * Error stack to use for `err.toString()` if `showStack` is `true`.
  58. * By default it uses the `stack` of the original error if you used one, otherwise it captures a new stack.
  59. */
  60. stack?: string;
  61. }
  62. /**
  63. * The `SimplePluginError` interface defines the properties available on all the the instances of `PluginError`.
  64. *
  65. * @internal
  66. */
  67. interface SimplePluginError extends Error {
  68. /**
  69. * Plugin name
  70. */
  71. plugin: string;
  72. /**
  73. * Boolean controlling if the stack will be shown in `err.toString()`.
  74. */
  75. showStack: boolean;
  76. /**
  77. * Boolean controlling if properties will be shown in `err.toString()`.
  78. */
  79. showProperties: boolean;
  80. /**
  81. * File name where the error occurred
  82. */
  83. fileName?: string;
  84. /**
  85. * Line number where the error occurred
  86. */
  87. lineNumber?: number;
  88. }
  89. }
  90. /**
  91. * Abstraction for error handling for Vinyl plugins
  92. */
  93. type PluginError<T = {}> = PluginError.SimplePluginError & T;
  94. declare const PluginError: PluginError.Constructor;
  95. export = PluginError;