{"version":3,"file":"BaseError.mjs","names":[],"sources":["../../src/error/BaseError.ts"],"sourcesContent":["/**\n * Copyright 2015 Blake Embrey\n * \n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * \n *     http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n *\n/\n\n/**\n * Original code is from project <https://github.com/blakeembrey/make-error-cause>.\n *\n * Changes to the original code:\n * - Use inspect from `object-inspect` insted of Node.js `util` module.\n * - Change `inspect()` method signature\n */\n\nimport makeError from 'make-error'\nimport inspect from 'object-inspect'\n\n/**\n * @internal\n */\nexport const SEPARATOR_TEXT = '\\n\\nThe following exception was the direct cause of the above exception:\\n\\n'\n\n/**\n * Create a new error instance of `cause` property support.\n */\nexport class BaseError extends makeError.BaseError {\n  protected constructor(\n    message?: string,\n    public cause?: Error\n  ) {\n    super(message)\n\n    Object.defineProperty(this, 'cause', {\n      value: cause,\n      writable: false,\n      enumerable: false,\n      configurable: false,\n    })\n  }\n\n  public inspect() {\n    return fullStack(this)\n  }\n}\n\n/**\n * Capture the full stack trace of any error instance.\n */\nexport function fullStack(error: Error | BaseError) {\n  const chain: Error[] = []\n  let cause: Error | undefined = error\n\n  while (cause) {\n    chain.push(cause)\n    cause = (cause as BaseError).cause\n  }\n\n  return chain.map((err) => inspect(err, { customInspect: false })).join(SEPARATOR_TEXT)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,MAAa,iBAAiB;;;;AAK9B,IAAa,YAAb,cAA+B,UAAU,UAAU;CACjD,AAAU,YACR,SACA,AAAO,OACP;AACA,QAAM,QAAQ;EAFP;AAIP,SAAO,eAAe,MAAM,SAAS;GACnC,OAAO;GACP,UAAU;GACV,YAAY;GACZ,cAAc;GACf,CAAC;;CAGJ,AAAO,UAAU;AACf,SAAO,UAAU,KAAK;;;;;;AAO1B,SAAgB,UAAU,OAA0B;CAClD,MAAM,QAAiB,EAAE;CACzB,IAAI,QAA2B;AAE/B,QAAO,OAAO;AACZ,QAAM,KAAK,MAAM;AACjB,UAAS,MAAoB;;AAG/B,QAAO,MAAM,KAAK,QAAQ,QAAQ,KAAK,EAAE,eAAe,OAAO,CAAC,CAAC,CAAC,KAAK,eAAe"}