Skip to content

Commit

Permalink
improve output diagnostic messages
Browse files Browse the repository at this point in the history
  • Loading branch information
jahudka committed Sep 8, 2023
1 parent c7218ca commit c0f5439
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion core/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"ioc",
"inversion of control"
],
"version": "0.0.39",
"version": "0.0.40",
"license": "MIT",
"author": {
"name": "Dan Kadera",
Expand Down
14 changes: 10 additions & 4 deletions core/cli/src/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class Checker {
for (const diagnostic of output.getPreEmitDiagnostics()) {
this.logger.log(
this.getDiagnosticCategoryLogLevel(diagnostic.getCategory()),
this.formatDiagnostic(diagnostic.getLineNumber(), diagnostic.getMessageText()),
this.formatDiagnostic(diagnostic.getMessageText(), diagnostic.getLineNumber()),
);
}
}
Expand All @@ -89,13 +89,19 @@ export class Checker {
}
}

private formatDiagnostic(line?: number, ...messages: (DiagnosticMessageChain | string)[]): string {
private formatDiagnostic(message: DiagnosticMessageChain | string, line?: number): string {
return line !== undefined
? `line ${line} in compiled container: ${this.formatDiagnosticMessage(message)}`
: `in compiled container: ${this.formatDiagnosticMessage(message)}`;
}

private formatDiagnosticMessage(...messages: (DiagnosticMessageChain | string)[]): string {
return messages.map((message) => {
if (typeof message === 'string') {
return line !== undefined ? `L${line}: ${message}` : message;
return message;
}

return this.formatDiagnostic(line, message.getMessageText(), ...message.getNext() ?? []);
return this.formatDiagnosticMessage(message.getMessageText(), ...message.getNext() ?? []);
}).join('\n');
}
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c0f5439

Please sign in to comment.