"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.registerIndexerErrorMetrics = exports.indexerError = exports.IndexerError = exports.INDEXER_ERROR_MESSAGES = exports.IndexerErrorCode = void 0;
const ts_custom_error_1 = require("ts-custom-error");
let indexerErrorMetrics;
const ERROR_BASE_URL = `https://github.com/graphprotocol/indexer/blob/master/docs/errors.md`;
var IndexerErrorCode;
(function (IndexerErrorCode) {
    IndexerErrorCode["IE001"] = "IE001";
    IndexerErrorCode["IE002"] = "IE002";
    IndexerErrorCode["IE003"] = "IE003";
    IndexerErrorCode["IE004"] = "IE004";
    IndexerErrorCode["IE005"] = "IE005";
    IndexerErrorCode["IE006"] = "IE006";
    IndexerErrorCode["IE007"] = "IE007";
    IndexerErrorCode["IE008"] = "IE008";
    IndexerErrorCode["IE009"] = "IE009";
    IndexerErrorCode["IE010"] = "IE010";
    IndexerErrorCode["IE011"] = "IE011";
    IndexerErrorCode["IE012"] = "IE012";
    IndexerErrorCode["IE013"] = "IE013";
    IndexerErrorCode["IE014"] = "IE014";
    IndexerErrorCode["IE015"] = "IE015";
    IndexerErrorCode["IE016"] = "IE016";
    IndexerErrorCode["IE017"] = "IE017";
    IndexerErrorCode["IE018"] = "IE018";
    IndexerErrorCode["IE019"] = "IE019";
    IndexerErrorCode["IE020"] = "IE020";
    IndexerErrorCode["IE021"] = "IE021";
    IndexerErrorCode["IE022"] = "IE022";
    IndexerErrorCode["IE023"] = "IE023";
    IndexerErrorCode["IE024"] = "IE024";
    IndexerErrorCode["IE025"] = "IE025";
    IndexerErrorCode["IE026"] = "IE026";
    IndexerErrorCode["IE027"] = "IE027";
    IndexerErrorCode["IE028"] = "IE028";
    IndexerErrorCode["IE029"] = "IE029";
    IndexerErrorCode["IE030"] = "IE030";
    IndexerErrorCode["IE031"] = "IE031";
    IndexerErrorCode["IE032"] = "IE032";
    IndexerErrorCode["IE033"] = "IE033";
    IndexerErrorCode["IE034"] = "IE034";
    IndexerErrorCode["IE035"] = "IE035";
    IndexerErrorCode["IE036"] = "IE036";
    IndexerErrorCode["IE037"] = "IE037";
    IndexerErrorCode["IE038"] = "IE038";
    IndexerErrorCode["IE039"] = "IE039";
    IndexerErrorCode["IE040"] = "IE040";
    IndexerErrorCode["IE041"] = "IE041";
    IndexerErrorCode["IE042"] = "IE042";
    IndexerErrorCode["IE043"] = "IE043";
    IndexerErrorCode["IE044"] = "IE044";
    IndexerErrorCode["IE045"] = "IE045";
    IndexerErrorCode["IE046"] = "IE046";
    IndexerErrorCode["IE047"] = "IE047";
    IndexerErrorCode["IE048"] = "IE048";
    IndexerErrorCode["IE049"] = "IE049";
    IndexerErrorCode["IE050"] = "IE050";
    IndexerErrorCode["IE051"] = "IE051";
    IndexerErrorCode["IE052"] = "IE052";
    IndexerErrorCode["IE053"] = "IE053";
    IndexerErrorCode["IE054"] = "IE054";
    IndexerErrorCode["IE055"] = "IE055";
    IndexerErrorCode["IE056"] = "IE056";
    IndexerErrorCode["IE057"] = "IE057";
})(IndexerErrorCode = exports.IndexerErrorCode || (exports.IndexerErrorCode = {}));
exports.INDEXER_ERROR_MESSAGES = {
    IE001: 'Failed to run database migrations',
    IE002: 'Invalid Ethereum URL',
    IE003: 'Failed to index network subgraph',
    IE004: 'Failed to synchronize with network',
    IE005: 'Failed to reconcile indexer and network',
    IE006: 'Failed to cross-check allocation state with contracts',
    IE007: 'Failed to check for network pause',
    IE008: 'Failed to check operator status for indexer',
    IE009: 'Failed to query subgraph deployments worth indexing',
    IE010: 'Failed to query indexer allocations',
    IE011: 'Failed to query claimable indexer allocations',
    IE012: 'Failed to register indexer',
    IE013: 'Failed to allocate: insufficient free stake',
    IE014: 'Failed to allocate: allocation not created on chain',
    IE015: 'Failed to close allocation',
    IE016: 'Failed to claim allocation',
    IE017: 'Failed to ensure default global indexing rule',
    IE018: 'Failed to query indexing status API',
    IE019: 'Failed to query proof of indexing',
    IE020: 'Failed to ensure subgraph deployment is indexing',
    IE021: 'Failed to migrate cost model',
    IE022: 'Failed to identify attestation signer for allocation',
    IE023: 'Failed to handle state channel message',
    IE024: 'Failed to connect to indexing status API',
    IE025: 'Failed to query indexer management API',
    IE026: 'Failed to deploy subgraph deployment',
    IE027: 'Failed to remove subgraph deployment',
    IE028: 'Failed to reassign subgraph deployment',
    IE029: 'Invalid Scalar-Receipt header provided',
    IE030: 'No Scalar-Receipt header provided',
    IE031: 'Invalid Scalar-Receipt value provided',
    IE032: 'Failed to process paid query',
    IE033: 'Failed to process free query',
    IE034: 'Not authorized as an operator for the indexer',
    IE035: 'Unhandled promise rejection',
    IE036: 'Unhandled exception',
    IE037: 'Failed to query disputable allocations',
    IE038: 'Failed to query epochs',
    IE039: 'Failed to store potential POI disputes',
    IE040: 'Failed to fetch POI disputes',
    IE041: 'Failed to query transfers to resolve',
    IE042: 'Failed to add transfer to the database',
    IE043: 'Failed to mark transfer as resolved',
    IE044: 'Failed to collect query fees on chain',
    IE045: 'Failed to queue transfers for resolving',
    IE046: 'Failed to resolve transfer',
    IE047: 'Failed to mark transfer as failed',
    IE048: 'Failed to withdraw query fees for allocation',
    IE049: 'Failed to clean up transfers for allocation',
    IE050: 'Transaction reverted due to gas limit being hit',
    IE051: 'Transaction reverted for unknown reason',
    IE052: 'Transaction aborted: maximum configured gas price reached',
    IE053: 'Failed to queue receipts for collecting',
    IE054: 'Failed to collect receipts in exchange for query fee voucher',
    IE055: 'Failed to redeem query fee voucher',
    IE056: 'Failed to remember allocation for collecting receipts later',
    IE057: 'Transaction reverted due to failing assertion in contract',
};
class IndexerError extends ts_custom_error_1.CustomError {
    constructor(code, cause) {
        super(exports.INDEXER_ERROR_MESSAGES[code]);
        this.code = code;
        this.explanation = `${ERROR_BASE_URL}#${code.toLowerCase()}`;
        this.cause = cause;
        if (indexerErrorMetrics) {
            indexerErrorMetrics.error.inc({ code: this.code });
        }
    }
}
exports.IndexerError = IndexerError;
function indexerError(code, cause) {
    return new IndexerError(code, cause);
}
exports.indexerError = indexerError;
function registerIndexerErrorMetrics(metrics) {
    indexerErrorMetrics = {
        error: new metrics.client.Counter({
            name: 'indexer_error',
            help: 'Indexer errors observed over time',
            labelNames: ['code'],
            registers: [metrics.registry],
        }),
    };
}
exports.registerIndexerErrorMetrics = registerIndexerErrorMetrics;
//# sourceMappingURL=errors.js.map