UNPKG

@informalsystems/quint

Version:

Core tool for the Quint specification language

50 lines 1.7 kB
"use strict"; /* ---------------------------------------------------------------------------------- * Copyright 2023 Informal Systems * Licensed under the Apache License, Version 2.0. * See LICENSE in the project root for license information. * --------------------------------------------------------------------------------- */ Object.defineProperty(exports, "__esModule", { value: true }); exports.fromQuintError = exports.sourceIdToLoc = void 0; /** * Error messages with source locations. * * @author Gabriela Moreira * * @module */ const lodash_1 = require("lodash"); const quintError_1 = require("./quintError"); /** * Map an identifier to the corresponding location in the source map, if possible. * @param sourceMap the source map * @param id the identifier to map * @returns the location, if found in the map, or the unknown location */ function sourceIdToLoc(sourceMap, id) { let sourceLoc = sourceMap.get(id); if (!sourceLoc) { console.error(`No source location found for ${id}. Please report a bug.`); return unknownLoc; } else { return sourceLoc; } } exports.sourceIdToLoc = sourceIdToLoc; function fromQuintError(sourceMap) { return error => { const loc = error.reference ? sourceMap.get(error.reference) : undefined; return { explanation: (0, quintError_1.quintErrorToString)(error), locs: (0, lodash_1.compact)([loc]), }; }; } exports.fromQuintError = fromQuintError; // the default error location that usually indicates a bug in our code const unknownLoc = { source: '<unknown>', start: { line: 0, col: 0, index: 0 }, }; //# sourceMappingURL=ErrorMessage.js.map