Skip to main content

Golem Documentation

Michael Bernstein

golem.diagnostics

Compiler diagnostics and human-readable error formatting for Golem.

Provides structured Diagnostic objects with file, line, and column coordinates, source snippet context windows, and visual caret indicators modeled after modern compiler diagnostics.

class Diagnostic

PYTHON
@dataclass(repr=False)
class Diagnostic:

Compiler diagnostic entry representing an error or warning.

Attributes

file

(str)

Default value: ''

line

(int | None)

Default value: None

column

(int | None)

Default value: None

message

(str)

Default value: ''

severity

(str)

Default value: 'error'

error_type

(str | None)

Default value: None

context

(str | None)

Default value: None

exception

(Exception | None)

Default value: None

from_exception

PYTHON
@classmethod
def from_exception(cls, exc: Exception, file: str | Path | None = None, severity: str = 'error') -> Diagnostic:

Construct a Diagnostic from an upstream syntax error or generic compilation exception.

from_resolver_warning

PYTHON
@classmethod
def from_resolver_warning(cls, warning: Any, file: str | Path | None = None, content: str | None = None) -> Diagnostic:

Construct a Diagnostic from an ASGResolver warning dictionary or object.

init

PYTHON
def __init__(self, file: str = '', line: int | None = None, column: int | None = None, message: str = '', severity: str = 'error', error_type: str | None = None, context: str | None = None, exception: Exception | None = None) -> None:

format_diagnostic

PYTHON
def format_diagnostic(error: Diagnostic | Exception, content_dir: Path | str | None = None) -> str:

Format clean AsciiDoc compiler diagnostics with source coordinates and context snippets.

Examples

PYTHON
>>> from golem.diagnostics import Diagnostic
>>> err = Diagnostic(file="docs/02-architecture.adoc", line=14, column=5, message="Unclosed attribute list")
>>> "Error in docs/02-architecture.adoc:14:5" in format_diagnostic(err)
True