"use strict";
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module iModels
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.ITwinError = exports.InUseLocksError = void 0;
const core_bentley_1 = require("@itwin/core-bentley");
/** @beta */
var InUseLocksError;
(function (InUseLocksError) {
    /**
     * type guard function that returns whether or not the passed in parameter is an [[InUseLocksError]].
     * it first checks [[ITwinError.isITwinError]] and then checks that the namespace property is "itwinjs-core" and the errorKey property is "in-use-locks".
     */
    function isInUseLocksError(error) {
        return ITwinError.isITwinError(error) && error.namespace === "itwinjs-core" && error.errorKey === "in-use-locks";
    }
    InUseLocksError.isInUseLocksError = isInUseLocksError;
    /** throws an error which passes the [[InUseLocksError.isInUseLocksError]] type guard function */
    function throwInUseLocksError(inUseLocks, message, metadata) {
        const errorObject = new Error();
        errorObject.name = "InUseLocksError"; // optional but makes it so that when the error is thrown and not caught we see InUseLocksError: 'message' instead of Error: 'message'
        Error.captureStackTrace(errorObject, throwInUseLocksError); // optional: whether we want to hide throwInUseLocksError or not from the stack. not super important
        const lockError = {
            namespace: "itwinjs-core",
            errorKey: "in-use-locks",
            message: message ?? "One or more objects are already locked by another briefcase.",
            metadata,
            inUseLocks,
        };
        Object.assign(errorObject, lockError);
        throw errorObject;
    }
    InUseLocksError.throwInUseLocksError = throwInUseLocksError;
})(InUseLocksError || (exports.InUseLocksError = InUseLocksError = {}));
/** @beta */
var ITwinError;
(function (ITwinError) {
    /** type guard function that returns whether or not the passed in parameter is an [[ITwinError]] */
    function isITwinError(error) {
        return error !== undefined && error !== null && typeof error === "object" && "namespace" in error && "errorKey" in error && "message" in error;
    }
    ITwinError.isITwinError = isITwinError;
    /** get the meta data associated with this ITwinError, if any. */
    function getMetaData(err) {
        return core_bentley_1.BentleyError.getMetaData(err.metadata);
    }
    ITwinError.getMetaData = getMetaData;
})(ITwinError || (exports.ITwinError = ITwinError = {}));
;
//# sourceMappingURL=ITwinError.js.map