Skip to content

Commit f701283

Browse files
committed
add .compilerError
1 parent ee6364a commit f701283

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/module/log.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { CompilerError } from '@syntaxs/compiler';
12
import { FULL_MODULE_NAME } from '../index.js';
23
import { arg } from './arg.js';
34
import chalk from 'chalk';
@@ -37,6 +38,17 @@ export namespace log {
3738
message.forEach(m => console.info(`${chalk.bgBlue(' INFO ')}`, m));
3839
}
3940

41+
/**
42+
* Logs a {@link CompilerError} as an error.
43+
* @param e The error.
44+
* @author efekos
45+
* @version 1.0.0
46+
* @since 0.0.1-alpha
47+
*/
48+
export function compilerError(e: CompilerError) {
49+
log.error(`${chalk.gray(`(${e.file}:${e.range.start.line}:${e.range.start.character})`)} ${e.message}`);
50+
}
51+
4052
/**
4153
* Logs every message given as a warning.
4254
* @param {any[]} message Messages to log.
@@ -86,6 +98,20 @@ export namespace log {
8698
process.exit(1);
8799
}
88100

101+
102+
/**
103+
* Alias for {@link log.compilerError}, but exits the process after logging.
104+
* @param e The error.
105+
* @author efekos
106+
* @version 1.0.0
107+
* @since 0.0.1-alpha
108+
*/
109+
export function compilerError(e: CompilerError) {
110+
log.compilerError(e);
111+
log.raw('', '', process.cwd(), FULL_MODULE_NAME);
112+
process.exit(1);
113+
}
114+
89115
/**
90116
* Alias for {@link log.raw}, but exits the process after logging.
91117
* @param {any[]} message Messages to log.
@@ -116,6 +142,21 @@ export namespace log {
116142
throw new ProgramError();
117143
}
118144

145+
146+
147+
/**
148+
* Alias for {@link log.compilerError}, but throws an error after logging.
149+
* @param e The error.
150+
* @author efekos
151+
* @version 1.0.0
152+
* @since 0.0.1-alpha
153+
*/
154+
export function compilerError(e: CompilerError) {
155+
log.compilerError(e);
156+
throw new ProgramError();
157+
}
158+
159+
119160
/**
120161
* Alias for {@link log.raw}, but throws an error after logging.
121162
* @param {any[]} message Messages to log.

0 commit comments

Comments
 (0)