diff --git a/vlib/v/eval/eval.v b/vlib/v/eval/eval.v index 822fbfa2e0..13e27de836 100644 --- a/vlib/v/eval/eval.v +++ b/vlib/v/eval/eval.v @@ -3,7 +3,6 @@ // that can be found in the LICENSE file. module eval -import os import v.ast import v.pref import v.util @@ -242,7 +241,7 @@ fn (e Eval) print_backtrace() { for i := e.back_trace.len - 1; i >= 0; i-- { t := e.back_trace[i] file_path := if path := e.trace_file_paths[t.file_idx] { - os.real_path(path) + util.path_styled_for_error_messages(path) } else { t.file_idx.str() } diff --git a/vlib/v/util/errors.v b/vlib/v/util/errors.v index e330b8d160..edb4d01db4 100644 --- a/vlib/v/util/errors.v +++ b/vlib/v/util/errors.v @@ -75,10 +75,10 @@ fn color(kind string, msg string) string { const normalised_workdir = os.wd_at_startup.replace('\\', '/') + '/' -// formatted_error - `kind` may be 'error' or 'warn' -pub fn formatted_error(kind string, omsg string, filepath string, pos token.Pos) string { - emsg := omsg.replace('main.', '') - mut path := filepath +// path_styled_for_error_messages returns the modified file path according +// to the user's preference (`VERROR_PATHS` env-var) +pub fn path_styled_for_error_messages(path_ string) string { + mut path := path_ verror_paths_override := os.getenv('VERROR_PATHS') if verror_paths_override == 'absolute' { path = os.real_path(path) @@ -90,7 +90,13 @@ pub fn formatted_error(kind string, omsg string, filepath string, pos token.Pos) path = path.replace_once(util.normalised_workdir, '') } } + return path +} +// formatted_error - `kind` may be 'error' or 'warn' +pub fn formatted_error(kind string, omsg string, filepath string, pos token.Pos) string { + emsg := omsg.replace('main.', '') + path := path_styled_for_error_messages(filepath) position := if filepath.len > 0 { '$path:${pos.line_nr + 1}:${mu.max(1, pos.col + 1)}:' } else {