UNPKG

@graphql-hive/cli

Version:

A CLI util to manage and control your GraphQL Hive

56 lines • 2.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getErrorReference = getErrorReference; exports.renderErrorReferenceMarkdown = renderErrorReferenceMarkdown; const errors_1 = require("./errors"); function categoryOf(error) { var _a; const category = [...errors_1.errorCategories].reverse().find(c => error.code >= c.start); return (_a = category === null || category === void 0 ? void 0 : category.name) !== null && _a !== void 0 ? _a : 'Unknown'; } function getErrorReference() { const exitCodes = [errors_1.ExitCode.SUCCESS, errors_1.ExitCode.ERROR, errors_1.ExitCode.TIMED_OUT, errors_1.ExitCode.BAD_INIT]; return { exitCodes: exitCodes.map(code => ({ code, name: errors_1.ExitCode[code], description: errors_1.exitCodeDescriptions[code], })), errors: [...errors_1.errorCatalog] .sort((a, b) => a.code - b.code) .map(error => ({ code: error.code, name: error.name, title: error.title, category: categoryOf(error), exitCode: error.exitCode, fix: error.fix, anchor: (0, errors_1.errorDocsAnchor)(error.code), })), }; } function escapeTableCell(value) { return value.replace(/\|/g, '\\|'); } function renderErrorReferenceMarkdown() { const reference = getErrorReference(); const lines = [ '## Errors', '', 'Every error message ends with its error code in brackets, for example `[103]`, and is printed to stderr. Details of a failed check or publish, such as the list of breaking changes, are printed to stdout.', '', '### Exit codes', '', '| Exit code | Name | Meaning |', '| --- | --- | --- |', ...reference.exitCodes.map(exitCode => `| ${exitCode.code} | \`${exitCode.name}\` | ${escapeTableCell(exitCode.description)} |`), '', '### Error codes', '', '| Code | Error | Exit code | Fix |', '| --- | --- | --- | --- |', ...reference.errors.map(error => `| <a id="${error.anchor}"></a>${error.code} | ${escapeTableCell(error.title)} (\`${error.name}\`) | ${error.exitCode} | ${escapeTableCell(error.fix)} |`), ]; return lines.join('\n'); } //# sourceMappingURL=error-docs.js.map