@digitalasset/daml-ledger
Version:
DAML Ledger API Node.js bindings
40 lines • 1.75 kB
JavaScript
;
// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
Object.defineProperty(exports, "__esModule", { value: true });
exports.HumanReadableReporter = void 0;
const Validation_1 = require("../validation/Validation");
function spellOutError(error) {
switch (error.errorType) {
case 'missing-key':
return `Missing key ${error.expectedKey} of type ${error.expectedType}`;
case 'unexpected-key':
return `Unexpected key ${error.key} found`;
case 'missing-type-tag':
return `Missing type tag (expected one of ${error.expectedTypeTags.join(', ')})`;
case 'unexpected-type-tag':
return `Unknown type tag ${error.actualTypeTag} (expected one of ${error.expectedTypeTags.join(', ')})`;
case 'type-error':
return `Type error, ${error.expectedType} expected but got ${error.actualType}`;
case 'invalid-integer-string':
return `Invalid string representation: "${error.actualValue}" cannot be parsed into an integer`;
}
}
function buildErrorMessage(tree, indent = 0) {
let errors = '';
for (const error of tree.errors) {
errors += `\n${' '.repeat(indent)}✗ ${spellOutError(error)}`;
}
for (const child in tree.children) {
if (!Validation_1.isValid(tree.children[child])) {
return `${errors}\n${' '.repeat(indent)}▸ ${child}${buildErrorMessage(tree.children[child], indent + 2)}`;
}
}
return errors;
}
exports.HumanReadableReporter = {
render(tree) {
return `! Validation error${buildErrorMessage(tree)}`;
}
};
//# sourceMappingURL=HumanReadableReporter.js.map