v / vlib / v2 / errors / util.v
33 lines · 28 sloc · 558 bytes · 7519f915ffdafd3229fdd8912f7d78481614cb35
Raw
1module errors
2
3import v2.token
4import term
5
6pub enum Kind {
7 warning
8 notice
9 error
10}
11
12pub fn (e Kind) str() string {
13 return match e {
14 .warning { 'warning' }
15 .notice { 'notice' }
16 .error { 'error' }
17 }
18}
19
20pub fn (e Kind) color(s string) string {
21 return match e {
22 .warning { term.yellow(s) }
23 .notice { term.blue(s) }
24 .error { term.red(s) }
25 }
26}
27
28pub fn error(msg string, details string, kind Kind, pos token.Position) {
29 eprintln(pos.str() + ' -> ' + term.bold(kind.color(kind.str())) + ': ' + msg)
30 if details.len > 0 {
31 eprintln(details)
32 }
33}
34