Skip to content

diagnostic

Renders compiler diagnostics and runtime errors.

Functions

Prints a compile.Diagnostic to stderr.

Parameters:

Name Type Description
diag Compiler diagnostic to render
color ? Optional color mode: :auto:, :never:, or :always:

Returns: nil

let result = compile.compile "bad.dol" "let =\n"
for diag = result.diagnostics
  diagnostic.print_compile_diag $diag

render_compile_diag diag :color?

Renders a compile.Diagnostic to a string.

Parameters:

Name Type Description
diag Compiler diagnostic to render
color ? Optional color mode: :auto:, :never:, or :always:

Returns: str

let text = diagnostic.render_compile_diag $diag color: :never:

Prints an error message and backtrace to stderr.

Parameters:

Name Type Description
err Value to render as the error message
backtrace ? Optional strand.Backtrace
color ? Optional color mode: :auto:, :never:, or :always:

Returns: nil

Errors:

  • Raises an error if backtrace is provided and is not strand.Backtrace
  • Raises an error if backtrace is omitted and there is no active handled exception
try
  throw "boom"
catch e
  diagnostic.print_error $e

render_error err :backtrace? :color?

Renders an error message and backtrace to a string.

Parameters:

Name Type Description
err Value to render as the error message
backtrace ? Optional strand.Backtrace
color ? Optional color mode: :auto:, :never:, or :always:

Returns: str

let text = try
  throw "boom"
catch e
  diagnostic.render_error $e color: :never: