1+ import { inspect } from 'node:util' ;
12import type { DiagnosticSourceFile } from '@css-modules-kit/core' ;
2- import { convertDiagnostic , convertSystemError , type Diagnostic , type SystemError } from '@css-modules-kit/core' ;
3+ import { convertDiagnostic , convertSystemError , type Diagnostic , SystemError } from '@css-modules-kit/core' ;
34import ts from 'typescript' ;
45import { formatDiagnostics } from './formatter.js' ;
56
67export interface Logger {
78 logDiagnostics ( diagnostics : Diagnostic [ ] ) : void ;
8- logSystemError ( error : SystemError ) : void ;
9+ logError ( error : unknown ) : void ;
910 logMessage ( message : string ) : void ;
1011}
1112
@@ -29,9 +30,17 @@ export function createLogger(cwd: string, pretty: boolean): Logger {
2930 ) ;
3031 process . stderr . write ( result ) ;
3132 } ,
32- logSystemError ( error : SystemError ) : void {
33- const result = formatDiagnostics ( [ convertSystemError ( error ) ] , host , pretty ) ;
34- process . stderr . write ( result ) ;
33+ logError ( error : unknown ) : void {
34+ // NOTE: SystemErrors are errors expected by the css-modules-kit specification and may occur within normal usage.
35+ // These errors are formatted clearly and concisely. No stack trace is output.
36+ //
37+ // All other errors are unexpected errors. To assist in debugging when these errors occur, a stack trace is output.
38+ if ( error instanceof SystemError ) {
39+ const result = formatDiagnostics ( [ convertSystemError ( error ) ] , host , pretty ) ;
40+ process . stderr . write ( result ) ;
41+ } else {
42+ process . stderr . write ( `${ inspect ( error , { colors : pretty } ) } \n` ) ;
43+ }
3544 } ,
3645 logMessage ( message : string ) : void {
3746 process . stdout . write ( `${ message } \n` ) ;
0 commit comments