mjdi

Search documentation

Search the mjdi v0.10.0 documentation

mjdi docsv0.10.0latest

The runtime error reference (P0-08)

mjdi's four runtime failure categories produce consistent, actionable

Source: mjdi/docs/runtime-error-reference.md

mjdi's four runtime failure categories produce consistent, actionable diagnostics: each names the service type, what operation failed, a stable MJDI-* identifier, and the remediation. Failure modes are unchanged from previous releases (raisable errors stay raisable; the abort stays an abort); only the message content gained structure. Pinned by tests/test_runtime_errors.mojo.

Compile-time failures are a different channel: they fail compilation with the MJDI-E* identifiers (see the validation output contract). The two channels are never mixed.

MJDI-R001 — scoped service resolved without a scope

Raised when a scoped provider (or a scoped-target alias) is resolved directly from the container. Carries: the service type, the resolution operation, and the remediation (create_scope() or the with_scope guard).

mjdi: 'Session' is registered with the scoped lifetime and can only be
resolved through a Scope (obtain one with container.create_scope() or the
with_scope guard), not directly from the container. [diagnostic MJDI-R001]

MJDI-R002 — value provider resolved before set_value

Raised when a value provider is resolved while its runtime value is unset. Carries: the type, the missing configuration fact, and two remediations (set_value now, or validate_runtime() up front at startup).

mjdi: 'Config' is registered as a value provider but no value has been
provided. Call container.set_value[Config](/docs/0.10.0/value) before resolving it —
or run container.validate_runtime() at startup to catch every missing
value up front. [diagnostic MJDI-R002]

Startup discipline: container.missing_values() / missing_value_count() / validate_runtime() report every unset value with type names before any service is constructed — the recommended way to turn this runtime error into a startup check.

MJDI-R003 — re-entrant resolution detected

Raised by the re-entrancy guard when a service is resolved while it is already being resolved higher on the same container/scope call stack (the factory-mediated cycles compile-time validation cannot see). Carries: the service type, the full resolution path (A -> B -> C), and the restructuring remediation. See docs/reentrancy.md.

MJDI-R004 — factory failure with preserved cause

Raised when a registered factory function throws. mjdi wraps the failure with the service type, the operation being attempted, and the original error text preserved verbatim as the underlying cause — the failure mode is unchanged (a raisable Error), and nothing is swallowed or replaced:

mjdi: the factory function for 'Client' raised while resolving the
transient instance. Underlying cause: connection refused
  Factories may raise; handle the error at the resolve site or fix the
  factory's unhandled condition. [diagnostic MJDI-R004]

The operation fragment distinguishes the three factory scopes: resolving the transient instance, constructing the singleton canonical instance, constructing the scoped canonical instance. An error thrown by a factory that itself calls resolve keeps the nested diagnostic's text in the cause (including its MJDI-* ID).

MJDI-A001 — inject marker read before resolution (abort)

Reading Inject[T].value() on a marker the container never populated aborts the process with:

mjdi: dependency of type 'UserRepository' was never resolved. Inject fields
are populated by the container; construct instances through
Container.resolve (or Injectable.create) instead of calling the struct
constructor directly. [diagnostic MJDI-A001]

The failure mode is a deliberate abort (it indicates a construction-contract violation the type system cannot express); it is verified by the crash-expected runner entry, which greps both the message and the stable ID.

Consistency rules

Every runtime diagnostic:

  1. names the concrete service type,
  2. states the operation that failed,
  3. carries its pinned ID at the end of the message,
  4. includes remediation (what to call, what to run, what to restructure),
  5. preserves any underlying cause verbatim (MJDI-R004; the re-entrancy path renders the live resolution path),
  6. never swallows an error: mjdi adds context, it does not replace or drop the original text.

mjdi/testing.py's assert_resolve_fails_with matches the raised message by fragment — use it to pin these diagnostics in your own tests, as the mjdi suite does.