error-helpers.js 808 B

12345678910111213141516171819
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.formatErrorCtor = void 0;
  4. function formatDependency(params, idx) {
  5. if (params === null) {
  6. return `at position #${idx}`;
  7. }
  8. const argName = params.split(",")[idx].trim();
  9. return `"${argName}" at position #${idx}`;
  10. }
  11. function composeErrorMessage(msg, e, indent = " ") {
  12. return [msg, ...e.message.split("\n").map(l => indent + l)].join("\n");
  13. }
  14. function formatErrorCtor(ctor, paramIdx, error) {
  15. const [, params = null] = ctor.toString().match(/constructor\(([\w, ]+)\)/) || [];
  16. const dep = formatDependency(params, paramIdx);
  17. return composeErrorMessage(`Cannot inject the dependency ${dep} of "${ctor.name}" constructor. Reason:`, error);
  18. }
  19. exports.formatErrorCtor = formatErrorCtor;