Skip to content

v.errors #

Description

v.errors formats compiler diagnostics with source excerpts, source positions, and template call stacks. DiagnosticRun shares path resolution and the most recently read source file across a report, and finds a line in that file from the line it found before. Its formatted_error and formatted_parser_diagnostic methods preserve the standalone formatter output. Reuse a run when reporting multiple checker or parser diagnostics. Use a fresh run for each report and keep the working directory, path display settings, and reported source files unchanged while it is in use.

fn details #

fn details(file &token.File, pos token.Position, row_padding int) string

details supports details handling for errors.

fn error #

fn error(msg string, details string, kind Kind, pos token.Position)

error supports error handling for errors.

fn formatted_error #

fn formatted_error(kind string, message string, a &flat.FlatAst, node flat.NodeId, pos token.Pos) string

formatted_error renders a compiler diagnostic with v1-compatible colors and source context.

fn formatted_parser_diagnostic #

fn formatted_parser_diagnostic(kind string, message string, a &flat.FlatAst, pos token.Pos) string

formatted_parser_diagnostic renders a colored parser diagnostic with template call-site context.

fn formatted_parser_error #

fn formatted_parser_error(message string, a &flat.FlatAst, pos token.Pos) string

formatted_parser_error renders a parser diagnostic with template call-site context.

fn formatted_source_error #

fn formatted_source_error(kind string, message string, file &token.File, pos token.Pos) string

formatted_source_error renders a diagnostic with v1-compatible colors for a source byte span. Under a #line directive, the location is the logical file and line. The excerpt then comes from the logical file, when it is another file that can be read, like C compilers show it; otherwise it is just the source line of the span, numbered as its logical line.

fn json_error #

fn json_error(kind string, message string, details []string, a &flat.FlatAst, node flat.NodeId, pos token.Pos) string

json_error renders a compiler diagnostic as one line of JSON. It locates the diagnostic like formatted_error does, so both forms report the same file, line and column.

fn json_located_message #

fn json_located_message(kind string, message string, details []string, path string, line int, column int) string

json_located_message renders a diagnostic of a file that the compiler holds no source of. Its span is the single column that was reported.

fn json_message #

fn json_message(kind string, message string, details []string) string

json_message renders a diagnostic that has no source position as one line of JSON.

fn json_output #

fn json_output() bool

json_output reports whether the compiler diagnostics are printed as JSON.

fn json_parser_diagnostic #

fn json_parser_diagnostic(kind string, message string, details []string, a &flat.FlatAst, pos token.Pos) string

json_parser_diagnostic renders a parser diagnostic as one line of JSON.

fn set_json_output #

fn set_json_output(enabled bool)

set_json_output selects the machine-readable form of the compiler diagnostics (-json-errors).

fn Kind.from #

fn Kind.from[W](input W) !Kind

from returns the Kind value of an integer or of a field name, or an error if there is none.

fn Reporter.from #

fn Reporter.from[W](input W) !Reporter

from returns the Reporter value of an integer or of a field name, or an error if there is none.

enum Kind #

enum Kind {
	warning
	notice
	error
}

Kind lists kind values used by errors.

fn (Kind) str #

fn (e Kind) str() string

str returns the string form for Kind.

fn (Kind) color #

fn (e Kind) color(s string) string

color supports color handling for Kind.

enum Reporter #

enum Reporter {
	scanner
	parser
	checker
	gen
}

Reporter lists reporter values used by errors.

struct CompilerMessage #

struct CompilerMessage {
pub:
	message   string
	details   string
	file_path string
	pos       token.Pos
	reporter  Reporter
}

CompilerMessage represents compiler message data used by errors.

struct DiagnosticRun #

struct DiagnosticRun {
mut:
	paths_known  bool
	absolute     bool
	workdir      string
	shown_paths  map[string]string
	source_known bool
	source_read  bool
	source_name  string
	source       string
	// Where the line `cursor_line` of `source` starts, 0 when no line was located yet.
	cursor_line   int
	cursor_offset int
}

DiagnosticRun holds what the diagnostics of one report share: the working directory, the resolved path of each file named so far and the text of the one named last. Resolving a path and reading a file take system calls that cost far more than formatting a message, and a report names the same few files again and again. A run assumes that neither the working directory nor the reported files change while it is used.

fn (DiagnosticRun) formatted_error #

fn (mut run DiagnosticRun) formatted_error(kind string, message string, a &flat.FlatAst, node flat.NodeId, pos token.Pos) string

formatted_error renders a compiler diagnostic like the function of the same name, sharing the work the diagnostics of this run have in common.

fn (DiagnosticRun) formatted_parser_diagnostic #

fn (mut run DiagnosticRun) formatted_parser_diagnostic(kind string, message string, a &flat.FlatAst, pos token.Pos) string

formatted_parser_diagnostic renders a parser diagnostic, sharing source and path lookups with the other diagnostics in this run.

struct Error #

struct Error {
	CompilerMessage
}

Error represents error data used by errors.

struct Warning #

struct Warning {
	CompilerMessage
}

Warning represents warning data used by errors.