error-helpers.js 826 B

1234567891011121314151617
  1. import { __read, __spread } from "tslib";
  2. function formatDependency(params, idx) {
  3. if (params === null) {
  4. return "at position #" + idx;
  5. }
  6. var argName = params.split(",")[idx].trim();
  7. return "\"" + argName + "\" at position #" + idx;
  8. }
  9. function composeErrorMessage(msg, e, indent) {
  10. if (indent === void 0) { indent = " "; }
  11. return __spread([msg], e.message.split("\n").map(function (l) { return indent + l; })).join("\n");
  12. }
  13. export function formatErrorCtor(ctor, paramIdx, error) {
  14. var _a = __read(ctor.toString().match(/constructor\(([\w, ]+)\)/) || [], 2), _b = _a[1], params = _b === void 0 ? null : _b;
  15. var dep = formatDependency(params, paramIdx);
  16. return composeErrorMessage("Cannot inject the dependency " + dep + " of \"" + ctor.name + "\" constructor. Reason:", error);
  17. }