topmark.core.errors¶
Core TopMark exceptions.
This module defines Click-free exception types that may be raised from any layer of TopMark, including registry construction, file-type resolution, TOML/template document handling, and higher-level orchestration code.
Each exception carries structured ErrorContext
metadata so callers can inspect machine-useful details such as the affected
path, qualified key, encoding, or additional diagnostic information.
CLI commands should catch these core exceptions and translate them into user-facing CLI errors with appropriate exit codes.
Design goals
- No Click dependency.
- Structured context via
ErrorContext. - Clear distinction between internal invariant failures and plausibly recoverable runtime errors.
- Preserve the underlying cause via exception chaining (
raise ... from exc).
ErrorContext
dataclass
¶
ErrorContext(
*,
message,
path=None,
qualified_key=None,
encoding=None,
diagnostics=None,
resolved=None,
details=(),
)
Structured context attached to a core TopMark error.
Attributes:
| Name | Type | Description |
|---|---|---|
message |
str
|
Human-readable error message, without CLI styling. |
path |
Path | None
|
Optional filesystem path associated with the failure. |
qualified_key |
str | None
|
Optional qualified key associated with the failure. |
encoding |
str | None
|
Optional encoding name relevant to the failure. |
diagnostics |
MutableDiagnosticLog | FrozenDiagnosticLog | None
|
Optional diagnostic log associated with the failure. |
resolved |
ResolvedTopmarkTomlSources | None
|
Optional resolved TOML-side state associated with the failure. |
details |
tuple[str, ...]
|
Optional tuple of additional diagnostic details. |
TopmarkError ¶
Bases: Exception
Base class for Click-free TopMark exceptions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
ErrorContext
|
Structured context describing the failure. |
required |
Source code in src/topmark/core/errors.py
ReservedNamespaceError ¶
Bases: TopmarkError
Raised when a reserved namespace is used by an ineligible registry entry.
This is intended for registry composition and registration APIs where the
topmark namespace is reserved for built-in entities and must not be
claimed by external overlays, plugins, or test fixtures unless they are
defined from within the TopMark package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
namespace
|
str
|
Reserved namespace that was used. |
required |
owner
|
str
|
Human-readable owner label for the offending entry. |
required |
entities
|
str
|
Registry entity category involved in the violation. |
required |
owner_module
|
str | None
|
Optional module path where the offending entry is defined. |
None
|
Source code in src/topmark/core/errors.py
UnsupportedFileTypeError ¶
Bases: TopmarkError
Raised when a file type is recognized but currently unsupported.
This distinguishes "unknown file type" from "known file type with no usable processor", which can be useful for diagnostics, reporting, and fallback handling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_type
|
str
|
Recognized file type identifier that is currently unsupported. |
required |
path
|
Path | None
|
Optional filesystem path associated with the lookup. |
None
|
Source code in src/topmark/core/errors.py
UnknownFileTypeError ¶
Bases: TopmarkError
Raised when a file type identifier cannot be resolved from a registry.
This error is typically raised by public registry helpers when a caller references a file type identifier that is not present in the effective file type view.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_type
|
str
|
File type identifier that could not be resolved. |
required |
path
|
Path | None
|
Optional filesystem path associated with the lookup. |
None
|
Source code in src/topmark/core/errors.py
AmbiguousFileTypeIdentifierError ¶
Bases: TopmarkError
Raised when an unqualified file type identifier resolves ambiguously.
This error is intended for lookup helpers that accept either unqualified or
qualified file type identifiers. Callers can recover by retrying with an
explicit qualified identifier of the form "<namespace>:<name>".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_type
|
str
|
Unqualified file type identifier supplied by the caller. |
required |
candidates
|
tuple[str, ...]
|
Candidate qualified keys that matched the identifier. |
required |
Source code in src/topmark/core/errors.py
InvalidRegistryIdentityError ¶
Bases: TopmarkError
Raised when a registry identifier or identity pair is malformed.
This error is intended for public registry APIs that accept identifiers such
as "<local_key>" or "<namespace>:<local_key>" and need to reject
malformed input explicitly rather than treating it as merely unknown.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Human-readable error message, without CLI styling. |
required |
identifier
|
str | None
|
Optional raw identifier string supplied by the caller. |
None
|
namespace
|
str | None
|
Optional namespace component when available. |
None
|
local_key
|
str | None
|
Optional namespace-local identifier when available. |
None
|
Source code in src/topmark/core/errors.py
ProcessorBindingError ¶
Bases: TopmarkError
Raised when explicit processor bindings are invalid or inconsistent.
This signals a registry-construction or registry-mutation invariant failure, such as an unknown bound file type identifier, an unknown processor qualified key, or a duplicate binding declaration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Human-readable error message. |
required |
file_type
|
str | None
|
Optional file type qualified key associated with the failed binding operation. |
None
|
Source code in src/topmark/core/errors.py
ProcessorRegistrationError ¶
Bases: TopmarkError
Base class for processor-registration failures.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Human-readable error message. |
required |
qualified_key
|
str
|
Processor qualified key associated with the failed registration. |
required |
Source code in src/topmark/core/errors.py
DuplicateProcessorRegistrationError ¶
Bases: ProcessorRegistrationError
Raised when a processor qualified key is already registered.
This condition may be recoverable depending on caller policy, for example by unregistering or replacing the existing entry before retrying.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qualified_key
|
str
|
Processor qualified key that is already present in the effective registry. |
required |
Source code in src/topmark/core/errors.py
DuplicateProcessorKeyError ¶
Bases: TopmarkError
Raised when multiple processor classes claim the same qualified key.
This signals an internal or overlay-composition invariant failure: the same qualified processor identity must not resolve to different processor classes in the effective processor registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qualified_key
|
str
|
Conflicting processor qualified key. |
required |
existing_class
|
str
|
Human-readable label for the already-associated class. |
required |
new_class
|
str
|
Human-readable label for the newly encountered class. |
required |
Source code in src/topmark/core/errors.py
InvalidPolicyError ¶
Bases: TopmarkError
Raised when a supplied policy value is invalid or malformed.
This is intended for API-facing policy overlays and other policy parsing boundaries where invalid scalar values should be rejected explicitly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Human-readable error message. |
required |
policy_key
|
str | None
|
Optional policy key associated with the invalid value. |
None
|
Source code in src/topmark/core/errors.py
InvalidReportScopeError ¶
Bases: TopmarkError
Raised when a supplied report-scope value is invalid or malformed.
This is intended for API-facing reporting/view boundaries where invalid scalar values should be rejected explicitly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Human-readable error message. |
required |
report_value
|
str | None
|
Optional invalid public report-scope token. |
None
|
Source code in src/topmark/core/errors.py
TomlDocumentError ¶
Bases: TopmarkError
Base class for TOML document parsing, rendering, and surgery errors.
This groups TOML-specific failures that arise while parsing, rendering, or structurally rewriting TOML documents.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Human-readable error message. |
required |
details
|
tuple[str, ...]
|
Optional structured diagnostic details. |
()
|
Source code in src/topmark/core/errors.py
TomlRenderError ¶
Bases: TomlDocumentError
Raised when TOML rendering fails due to invalid inputs or invariants.
Source code in src/topmark/core/errors.py
TomlParseError ¶
Bases: TomlDocumentError
Raised when a TOML document cannot be parsed.
Source code in src/topmark/core/errors.py
TomlSurgeryError ¶
Bases: TomlDocumentError
Raised when structural TOML editing fails or required TOML shape invariants are violated.
Source code in src/topmark/core/errors.py
TemplateError ¶
Bases: TomlDocumentError
Base class for annotated config-template editing and validation errors.
Template errors are narrower than generic TOML document errors: they refer specifically to the annotated configuration template and the presentation- preserving helpers that edit or validate it.
Source code in src/topmark/core/errors.py
TemplateEditError ¶
Bases: TemplateError
Raised when annotated config-template editing fails.
Source code in src/topmark/core/errors.py
TemplateValidationError ¶
Bases: TemplateError
Raised when an annotated config-template result fails validation.
Source code in src/topmark/core/errors.py
ConfigValidationError ¶
Bases: TopmarkError
Raised when config validation fails.
Config validity follows the staged config-loading validation semantics: TOML-source diagnostics, merged-config diagnostics, and runtime-applicability diagnostics are evaluated together. In non-strict mode, validation fails only when at least one stage contains an error diagnostic. In strict mode, validation fails when any stage contains either a warning or an error diagnostic.
This error is used for both immmutale FrozenConfig
and mutable MutableConfig validation helpers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
validation_logs
|
MutableValidationLogs | FrozenValidationLogs
|
Staged validation logs attached to the config being validated. |
required |
strict
|
bool
|
Effective resolved strictness used for staged config/preflight validation. This is the boolean strictness that was actually applied after TOML resolution and any CLI/API override. |
required |
details
|
tuple[str, ...]
|
Optional structured diagnostic details. |
()
|