diff --git a/src/diagnostics.ts b/src/diagnostics.ts index bf8b3059e..944fa1796 100644 --- a/src/diagnostics.ts +++ b/src/diagnostics.ts @@ -2,7 +2,7 @@ import * as fs from "fs" import chalk from "chalk" import { Syntax } from "./ast"; -import {format, MapLike, FormatArg, countDigits, mapValues, prettyPrint, assert} from "./util"; +import {format, MapLike, FormatArg, countDigits, mapValues, prettyPrint, assert, isPlainObject, isPrimitive, JsonObject, Json} from "./util"; import { BOLT_DIAG_NUM_EXTRA_LINES } from "./constants"; import { TextPos, TextFile, TextSpan } from "./text"; @@ -125,7 +125,7 @@ export class DiagnosticPrinter { out += chalk.bold.yellow(`${span.file.origPath}:${span.start.line}:${span.start.column}: `); } if (diagnostic.args !== undefined) { - out += format(diagnostic.message, mapValues(diagnostic.args, prettyPrint)) + '\n'; + out += format(diagnostic.message, diagnostic.args) + '\n'; } else { out += diagnostic.message + '\n'; } diff --git a/src/frontend.ts b/src/frontend.ts index b342348ef..3dcf5e877 100644 --- a/src/frontend.ts +++ b/src/frontend.ts @@ -19,7 +19,7 @@ import { TypeChecker } from "./types" import { CheckInvalidFilePaths, CheckTypeAssignments, CheckReferences } from "./checks" import { SymbolResolver, BoltSymbolResolutionStrategy } from "./resolver" import { Evaluator } from "./evaluator" -import { getNodeLanguage, ParseError, ScanError } from "./common" +import { getNodeLanguage, ParseError, ScanError, describeKind } from "./common" import { Package, loadPackageMetadata } from "./package" import { TextFile } from "./text" import { Scanner } from "./scanner" @@ -191,7 +191,7 @@ export class Frontend { } else if (e instanceof ParseError) { this.diagnostics.add({ message: E_PARSE_ERROR, - args: { actual: kindToString(e.actual.kind), expected: e.expected.map(kindToString) }, + args: { actual: describeKind(e.actual.kind), expected: e.expected.map(describeKind) }, node: e.actual, severity: 'fatal', }); diff --git a/src/util.ts b/src/util.ts index feab105e7..e0bc22951 100644 --- a/src/util.ts +++ b/src/util.ts @@ -627,6 +627,9 @@ type FormatModifierFn = (value: any) => any; const FORMAT_MODIFIERS: MapLike = { enum(elements) { return enumOr(elements); + }, + pretty(value) { + return value.map(prettyPrint); } } @@ -643,17 +646,20 @@ export function format(message: string, data: MapLike) { switch (mode) { case FormatScanMode.ScanningParamModifier: if (ch === '}') { - modifiers.push(modifierName); - push(); - } else if (ch === ':') { if (modifierName.length === 0) { throw new Error(`Parameter modfifier name in format string is empty.`) } modifiers.push(modifierName); - modifierName = ''; + push(); + } else if (ch === ':') { + if (modifierName.length > 0) { + modifiers.push(modifierName); + modifierName = ''; + } } else { modifierName += ch; } + break; case FormatScanMode.ScanningParamName: if (ch === '}') { push();