@mongosh/errors
Advanced tools
Comparing version
@@ -29,3 +29,3 @@ import { expect } from 'chai'; | ||
expect(error.name).to.be.equal('MongoshInternalError'); | ||
expect(error.message).to.be.equal('[COMMON-90001] Something went wrong.\nThis is an error inside Mongosh. Please file a bug report for the MONGOSH project here: https://jira.mongodb.org.'); | ||
expect(error.message).to.be.equal('[COMMON-90001] Something went wrong.\nThis is an error inside mongosh. Please file a bug report for the MONGOSH project here: https://jira.mongodb.org/projects/MONGOSH/issues.'); | ||
expect(error.code).to.be.equal(CommonErrors.UnexpectedInternalError); | ||
@@ -32,0 +32,0 @@ expect(error.scope).to.be.equal('COMMON'); |
@@ -36,3 +36,3 @@ import { CommonErrors } from './common-errors'; | ||
`${message} | ||
This is an error inside Mongosh. Please file a bug report for the MONGOSH project here: https://jira.mongodb.org.`, | ||
This is an error inside mongosh. Please file a bug report for the MONGOSH project here: https://jira.mongodb.org/projects/MONGOSH/issues.`, | ||
CommonErrors.UnexpectedInternalError, | ||
@@ -39,0 +39,0 @@ metadata |
@@ -33,3 +33,3 @@ "use strict"; | ||
super('MongoshInternalError', `${message} | ||
This is an error inside Mongosh. Please file a bug report for the MONGOSH project here: https://jira.mongodb.org.`, common_errors_1.CommonErrors.UnexpectedInternalError, metadata); | ||
This is an error inside mongosh. Please file a bug report for the MONGOSH project here: https://jira.mongodb.org/projects/MONGOSH/issues.`, common_errors_1.CommonErrors.UnexpectedInternalError, metadata); | ||
} | ||
@@ -36,0 +36,0 @@ } |
{ | ||
"name": "@mongosh/errors", | ||
"version": "0.13.2", | ||
"version": "0.14.0", | ||
"description": "MongoDB Shell Errors Package", | ||
@@ -26,5 +26,5 @@ "homepage": "https://github.com/mongodb-js/mongosh", | ||
"prepublish": "npm run compile-ts", | ||
"generate-error-overview": "ts-node scripts/extract-errors.ts .. ../../error-overview.md" | ||
"generate-error-overview": "ts-node scripts/extract-errors.ts .. ../../error-overview.md ../../error-overview.rst" | ||
}, | ||
"gitHead": "7517f44ef756760060666c20f0de964564fb3aa2" | ||
"gitHead": "39df2de64c8448b4afaee905a038d615345a1e44" | ||
} |
@@ -89,3 +89,3 @@ # `@mongosh/errors` | ||
``` | ||
This is an error inside Mongosh. Please file a bug report for the MONGOSH project here: https://jira.mongodb.org. | ||
This is an error inside mongosh. Please file a bug report for the MONGOSH project here: https://jira.mongodb.org/projects/MONGOSH/issues. | ||
``` | ||
@@ -92,0 +92,0 @@ |
@@ -13,4 +13,6 @@ import { promises as fs } from 'fs'; | ||
(async function() { | ||
const pathToPackages = path.resolve(process.argv[process.argv.length - 2]); | ||
const pathToOutput = path.resolve(process.argv[process.argv.length - 1]); | ||
const pathToPackages = path.resolve(process.argv[process.argv.length - 3]); | ||
const pathToMarkdownOutput = path.resolve(process.argv[process.argv.length - 2]); | ||
const pathToRestructuredOutput = path.resolve(process.argv[process.argv.length - 1]); | ||
if (!pathToPackages || !(await isDirectory(pathToPackages))) { | ||
@@ -56,6 +58,9 @@ ux.fatal('Could not find given packages directory:', pathToPackages); | ||
await renderErrorOverview(pathToOutput, packageErrors); | ||
await renderErrorOverviewMarkdown(pathToMarkdownOutput, packageErrors); | ||
await renderErrorOverviewRestructured(pathToRestructuredOutput, packageErrors); | ||
ux.success('👏👏👏👏'); | ||
ux.success(`Wrote generated overview page to: ${pathToOutput}`); | ||
ux.success('Wrote generated overview page:'); | ||
ux.success(` -> markdown: ${pathToMarkdownOutput}`); | ||
ux.success(` -> restructured: ${pathToRestructuredOutput}`); | ||
ux.success('👏👏👏👏'); | ||
@@ -203,3 +208,3 @@ })().catch(err => process.nextTick(() => { throw err; })); | ||
async function renderErrorOverview(outputPath: string, packageErrors: PackageErrors[]): Promise<void> { | ||
async function renderErrorOverviewMarkdown(outputPath: string, packageErrors: PackageErrors[]): Promise<void> { | ||
const templateContent = await fs.readFile( | ||
@@ -221,1 +226,52 @@ path.resolve(__dirname, 'error-overview.tmpl.md'), | ||
} | ||
async function renderErrorOverviewRestructured(outputPath: string, packageErrors: PackageErrors[]): Promise<void> { | ||
const restructuredErrors = packageErrors.map(pe => { | ||
return { | ||
package: pe.package, | ||
packageHeadlineSeparator: '-'.repeat(pe.package.length), | ||
errors: pe.errors.map(convertMarkdownToRestructured) | ||
}; | ||
}); | ||
const templateContent = await fs.readFile( | ||
path.resolve(__dirname, 'error-overview.tmpl.rst'), | ||
{ encoding: 'utf-8' } | ||
); | ||
const template = compile(templateContent); | ||
const output = template({ | ||
packages: restructuredErrors | ||
}); | ||
await fs.writeFile( | ||
outputPath, | ||
output, | ||
{ encoding: 'utf-8' } | ||
); | ||
} | ||
function convertMarkdownToRestructured(error: PackageError): PackageError & { codeHeadlineSeparator: string } { | ||
// every odd element is _inside_ a code block (```) | ||
const docWithCodeBlocks = error.documentation.split('```'); | ||
for (let i = 0; i < docWithCodeBlocks.length; i++) { | ||
const text = docWithCodeBlocks[i]; | ||
let restructured = ''; | ||
if (i % 2 === 1) { | ||
// we have a code block - prefix and indent | ||
const codeLines = text.split('\n'); | ||
restructured += '.. code-block:: ' + codeLines.shift() + '\n\n'; | ||
restructured += codeLines.map(l => ' ' + l).join('\n'); | ||
} else { | ||
const inlineCode = /`([^`]*)`/g; | ||
restructured = text.replace(inlineCode, (_, code) => '``' + code + '``'); | ||
} | ||
docWithCodeBlocks[i] = restructured; | ||
} | ||
return { | ||
code: error.code, | ||
codeHeadlineSeparator: '~'.repeat(error.code.length + 4), | ||
documentation: docWithCodeBlocks.join('\n') | ||
}; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
51655
19.65%23
21.05%637
8.33%