UNPKG

@trapi/metadata

Version:

Generate REST-API metadata scheme from TypeScript Decorators.

41 lines 1.71 kB
"use strict"; /* * Copyright (c) 2021. * Author Peter Placzek (tada5hi) * For the full copyright and license information, * view the LICENSE file that was distributed with this source code. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.prettyTroubleCause = exports.prettyLocationOfNode = exports.ResolverError = void 0; const node_path_1 = require("node:path"); const error_1 = require("../error"); class ResolverError extends error_1.BaseError { constructor(message, node, onlyCurrent = false) { super(message); if (node) { this.message = `${message}\n${prettyLocationOfNode(node)}\n${prettyTroubleCause(node, onlyCurrent)}`; } } } exports.ResolverError = ResolverError; function prettyLocationOfNode(node) { const sourceFile = node.getSourceFile(); const token = node.getFirstToken() || node.parent.getFirstToken(); const start = token ? `:${sourceFile.getLineAndCharacterOfPosition(token.getStart()).line + 1}` : ''; const end = token ? `:${sourceFile.getLineAndCharacterOfPosition(token.getEnd()).line + 1}` : ''; const normalizedPath = (0, node_path_1.normalize)(`${sourceFile.fileName}${start}${end}`); return `At: ${normalizedPath}.`; } exports.prettyLocationOfNode = prettyLocationOfNode; function prettyTroubleCause(node, onlyCurrent = false) { let name; if (onlyCurrent || !node.parent) { name = node.pos !== -1 ? node.getText() : node.name.text; } else { name = node.parent.pos !== -1 ? node.parent.getText() : node.parent.name.text; } return `This was caused by '${name}'`; } exports.prettyTroubleCause = prettyTroubleCause; //# sourceMappingURL=error.js.map