index.d.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. export = OError;
  2. /**
  3. * Light-weight helpers for handling JavaScript Errors in node.js and the
  4. * browser.
  5. */
  6. declare class OError extends Error {
  7. /**
  8. * Tag debugging information onto any error (whether an OError or not) and
  9. * return it.
  10. *
  11. * @param {Error} error the error to tag
  12. * @param {string} [message] message with which to tag `error`
  13. * @param {Object} [info] extra data with wich to tag `error`
  14. * @return {Error} the modified `error` argument
  15. */
  16. static tag(error: Error, message?: string, info?: any): Error;
  17. /**
  18. * The merged info from any `tag`s on the given error.
  19. *
  20. * If an info property is repeated, the last one wins.
  21. *
  22. * @param {Error | null | undefined} error any errror (may or may not be an `OError`)
  23. * @return {Object}
  24. */
  25. static getFullInfo(error: Error): any;
  26. /**
  27. * Return the `stack` property from `error`, including the `stack`s for any
  28. * tagged errors added with `OError.tag` and for any `cause`s.
  29. *
  30. * @param {Error | null | undefined} error any error (may or may not be an `OError`)
  31. * @return {string}
  32. */
  33. static getFullStack(error: Error): string;
  34. /**
  35. * @param {string} message as for built-in Error
  36. * @param {Object} [info] extra data to attach to the error
  37. * @param {Error} [cause] the internal error that caused this error
  38. */
  39. constructor(message: string, info?: any, cause?: Error);
  40. info: any;
  41. cause: Error;
  42. /** @private @type {Array<TaggedError>} */
  43. private _oErrorTags;
  44. /**
  45. * Set the extra info object for this error.
  46. *
  47. * @param {Object | null | undefined} info extra data to attach to the error
  48. * @return {this}
  49. */
  50. withInfo(info: any): OError;
  51. /**
  52. * Wrap the given error, which caused this error.
  53. *
  54. * @param {Error} cause the internal error that caused this error
  55. * @return {this}
  56. */
  57. withCause(cause: Error): OError;
  58. }