Launch Week Day 4: Introducing Data Exports.Learn More
Socket
Book a DemoSign in
Socket

@mongosh/errors

Package Overview
Dependencies
Maintainers
11
Versions
127
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mongosh/errors - npm Package Compare versions

Comparing version
0.13.2
to
0.14.0
generated/.gitkeep

Sorry, the diff of this file is not supported yet

+91
# mongosh Error Codes Overview
To quickly find an error by its code, search for the code in this overview.
## Table of Contents
* [@mongosh/async-rewriter2](#@mongosh/async-rewriter2)
* [@mongosh/cli-repl](#@mongosh/cli-repl)
* [@mongosh/errors](#@mongosh/errors)
* [@mongosh/shell-api](#@mongosh/shell-api)
## @mongosh/async-rewriter2
#### `ASYNC-10012`
Signals the use of a Mongosh API call in a place where it is not supported.
This occurs inside of constructors and (non-async) generator functions.
Examples causing error:
```javascript
class SomeClass {
constructor() {
this.list = db.coll.find().toArray();
}
}
function*() {
yield* db.coll.find().toArray();
}
```
**Solution: Do not use calls directly in such functions. If necessary, place these calls in an inner 'async' function.**
## @mongosh/cli-repl
#### `CLIREPL-10001`
Signals that the currently installed Node version does not match the one expected by mongosh.
See the output for further details on the required Node version.
## @mongosh/errors
#### `COMMON-10001`
Signals calling an API method with an invalid argument.
**Solution: See the error output for details on allowed argument values.**
#### `COMMON-10002`
Signals calling an API method that is not allowed in the current state.
**Solution: See the error output for details.**
#### `COMMON-10003`
Signals calling an API method that has been deprecated or using an argument or option of an API method that has been deprecated
and therefore is no longer supported.
**Solution: See the error output for details on alternatives or consult the official documentation.**
#### `COMMON-10004`
Signals an error while running a specific command against the database.
**Solution: Check the error output for more details and ensure the database is healthy and available.**
#### `COMMON-90001`
Signals an unexpected internal error of mongosh.
**Please file a bug report for the `MONGOSH` project here: https://jira.mongodb.org.**
#### `COMMON-90002`
Signals usage of a method that is not implemented yet.
**See the error output for details.**
## @mongosh/shell-api
#### `SHAPI-10001`
Signals calling a method that requires sharding for a collection that is not sharded
or a database that does not have sharding enabled.
**Solution: Be sure to enable sharding on the database or that the collection is sharded.**
#### `SHAPI-10002`
Signals calling a method requiring a replica set without being connected to a replica set.
**Solution: Make sure you are connected to a replica set.**
#### `SHAPI-10003`
Signals calling a method that requires to be connected to a `mongos` instead of just a `mongod`.
**Solution: Ensure you are connected to a `mongos` instances.**
#### `SHAPI-10004`
Signals calling an operation that requires an active database connection without being connected.
**Solution: Connect to a database before executing the operation.**
#### `SHAPI-10005`
Signals calling a method that requires a Mongo object with field-level encryption options
when none were passed.
**Solution: Create a new Mongo object with the correct field-level encryption options first.**
@mongosh/async-rewriter2
------------------------
``ASYNC-10012``
~~~~~~~~~~~~~~~
Signals the use of a Mongosh API call in a place where it is not supported.
This occurs inside of constructors and (non-async) generator functions.
Examples causing error:
.. code-block:: javascript
class SomeClass {
constructor() {
this.list = db.coll.find().toArray();
}
}
function*() {
yield* db.coll.find().toArray();
}
**Solution: Do not use calls directly in such functions. If necessary, place these calls in an inner 'async' function.**
@mongosh/cli-repl
-----------------
``CLIREPL-10001``
~~~~~~~~~~~~~~~~~
Signals that the currently installed Node version does not match the one expected by mongosh.
See the output for further details on the required Node version.
@mongosh/errors
---------------
``COMMON-10001``
~~~~~~~~~~~~~~~~
Signals calling an API method with an invalid argument.
**Solution: See the error output for details on allowed argument values.**
``COMMON-10002``
~~~~~~~~~~~~~~~~
Signals calling an API method that is not allowed in the current state.
**Solution: See the error output for details.**
``COMMON-10003``
~~~~~~~~~~~~~~~~
Signals calling an API method that has been deprecated or using an argument or option of an API method that has been deprecated
and therefore is no longer supported.
**Solution: See the error output for details on alternatives or consult the official documentation.**
``COMMON-10004``
~~~~~~~~~~~~~~~~
Signals an error while running a specific command against the database.
**Solution: Check the error output for more details and ensure the database is healthy and available.**
``COMMON-90001``
~~~~~~~~~~~~~~~~
Signals an unexpected internal error of mongosh.
**Please file a bug report for the ``MONGOSH`` project here: https://jira.mongodb.org.**
``COMMON-90002``
~~~~~~~~~~~~~~~~
Signals usage of a method that is not implemented yet.
**See the error output for details.**
@mongosh/shell-api
------------------
``SHAPI-10001``
~~~~~~~~~~~~~~~
Signals calling a method that requires sharding for a collection that is not sharded
or a database that does not have sharding enabled.
**Solution: Be sure to enable sharding on the database or that the collection is sharded.**
``SHAPI-10002``
~~~~~~~~~~~~~~~
Signals calling a method requiring a replica set without being connected to a replica set.
**Solution: Make sure you are connected to a replica set.**
``SHAPI-10003``
~~~~~~~~~~~~~~~
Signals calling a method that requires to be connected to a ``mongos`` instead of just a ``mongod``.
**Solution: Ensure you are connected to a ``mongos`` instances.**
``SHAPI-10004``
~~~~~~~~~~~~~~~
Signals calling an operation that requires an active database connection without being connected.
**Solution: Connect to a database before executing the operation.**
``SHAPI-10005``
~~~~~~~~~~~~~~~
Signals calling a method that requires a Mongo object with field-level encryption options
when none were passed.
**Solution: Create a new Mongo object with the correct field-level encryption options first.**
{{#each packages}}
{{package}}
{{packageHeadlineSeparator}}
{{#each errors}}
``{{code}}``
{{codeHeadlineSeparator}}
{{{documentation}}}
{{/each}}
{{/each}}
+1
-0

@@ -10,1 +10,2 @@ Irina Shestak <shestak.irina@gmail.com>

github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Massimiliano Marcon <me@marcon.me>
+1
-1

@@ -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 @@ }

@@ -1,1 +0,1 @@

{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,mDAA+C;AA4F7C,6FA5FO,4BAAY,OA4FP;AA1Fd,SAAS,qBAAqB,CAAC,IAA+B;IAC5D,IAAI,CAAC,IAAI,EAAE;QACT,OAAO,SAAS,CAAC;KAClB;IACD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;IAC7C,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACvC,CAAC;AA2EC,sDAAqB;AAzEvB,MAAe,gBAAiB,SAAQ,KAAK;IAK3C,YAAY,IAAY,EAAE,OAAe,EAAE,IAAa,EAAE,QAAiB;QACzE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QAC/C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;QACzC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF;AA8DC,4CAAgB;AA5DlB,MAAM,mBAAoB,SAAQ,gBAAgB;IAChD,YAAY,OAA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,uBAAuB,EACpC,QAAQ,CACT,CAAC;IACJ,CAAC;CACF;AA+CC,oDAAoB;AA7CtB,MAAM,yBAA0B,SAAQ,gBAAgB;IACtD,YAAY,OAAe,EAAE,IAAa,EAAE,QAAiB;QAC3D,KAAK,CAAC,2BAA2B,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC9D,CAAC;CACF;AA2CC,8DAAyB;AAzC3B,MAAM,wBAAyB,SAAQ,gBAAgB;IACrD,YAAY,OAAe,EAAE,IAAa,EAAE,QAAiB;QAC3D,KAAK,CAAC,0BAA0B,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC7D,CAAC;CACF;AAoCC,4DAAwB;AAlC1B,MAAM,cAAe,SAAQ,gBAAgB;IAC3C,YAAY,OAAe,EAAE,IAAa,EAAE,QAAiB;QAC3D,KAAK,CAAC,gBAAgB,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;IACnD,CAAC;CACF;AA2BC,wCAAc;AAzBhB,MAAM,sBAAuB,SAAQ,gBAAgB;IACnD,YAAY,OAAe,EAAE,QAAiB;QAC5C,KAAK,CACH,wBAAwB,EACxB,OAAO,EACP,4BAAY,CAAC,UAAU,EACvB,QAAQ,CACT,CAAC;IACJ,CAAC;CACF;AAqBC,wDAAsB;AAnBxB,MAAM,oBAAqB,SAAQ,gBAAgB;IACjD,YAAY,OAAe,EAAE,QAAiB;QAC5C,KAAK,CACH,sBAAsB,EACtB,WAAW,OAAO,mFAAmF,EACrG,4BAAY,CAAC,aAAa,EAC1B,QAAQ,CACT,CAAC;IACJ,CAAC;CACF;AAWC,oDAAoB"}
{
"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')
};
}