"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CommonErrors = exports.MongoshCommandFailed = exports.MongoshDeprecatedError = exports.MongoshUnimplementedError = exports.MongoshInvalidInputError = exports.MongoshInternalError = exports.MongoshRuntimeError = exports.MongoshWarning = exports.MongoshBaseError = void 0;
exports.getScopeFromErrorCode = getScopeFromErrorCode;
exports.isShouldReportAsBugError = isShouldReportAsBugError;
const common_errors_1 = require("./common-errors");
Object.defineProperty(exports, "CommonErrors", { enumerable: true, get: function () { return common_errors_1.CommonErrors; } });
function getScopeFromErrorCode(code) {
    if (!code) {
        return undefined;
    }
    const match = /^([a-zA-Z0-9]+)-/.exec(code);
    return !match ? undefined : match[1];
}
function isShouldReportAsBugError(err) {
    return err?.code === common_errors_1.CommonErrors.UnexpectedInternalError;
}
class MongoshBaseError extends Error {
    constructor(name, message, code, metadata) {
        super(code ? `[${code}] ${message}` : message);
        this.name = name;
        this.code = code;
        this.scope = getScopeFromErrorCode(code);
        this.metadata = metadata;
    }
}
exports.MongoshBaseError = MongoshBaseError;
class MongoshRuntimeError extends MongoshBaseError {
    constructor(message, code, metadata) {
        super('MongoshRuntimeError', message, code, metadata);
    }
}
exports.MongoshRuntimeError = MongoshRuntimeError;
class MongoshInternalError extends MongoshBaseError {
    constructor(message, metadata) {
        super('MongoshInternalError', message, common_errors_1.CommonErrors.UnexpectedInternalError, metadata);
    }
}
exports.MongoshInternalError = MongoshInternalError;
class MongoshUnimplementedError extends MongoshBaseError {
    constructor(message, code, metadata) {
        super('MongoshUnimplementedError', message, code, metadata);
    }
}
exports.MongoshUnimplementedError = MongoshUnimplementedError;
class MongoshInvalidInputError extends MongoshBaseError {
    constructor(message, code, metadata) {
        super('MongoshInvalidInputError', message, code, metadata);
    }
}
exports.MongoshInvalidInputError = MongoshInvalidInputError;
class MongoshWarning extends MongoshBaseError {
    constructor(message, code, metadata) {
        super('MongoshWarning', message, code, metadata);
    }
}
exports.MongoshWarning = MongoshWarning;
class MongoshDeprecatedError extends MongoshBaseError {
    constructor(message, metadata) {
        super('MongoshDeprecatedError', message, common_errors_1.CommonErrors.Deprecated, metadata);
    }
}
exports.MongoshDeprecatedError = MongoshDeprecatedError;
class MongoshCommandFailed extends MongoshBaseError {
    constructor(message, metadata) {
        super('MongoshCommandFailed', `Command ${message} returned ok: 0. To see the raw results of the command, use 'runCommand' instead.`, common_errors_1.CommonErrors.CommandFailed, metadata);
    }
}
exports.MongoshCommandFailed = MongoshCommandFailed;
//# sourceMappingURL=index.js.map