MINK
Language

MINK: error system and diagnostics specification

Status: Planning / Specification Version: 0.1.0

1. Objective

MINK treats error handling and diagnostics as a first-class language capability.

The goal is not merely to report failure. MINK should help developers understand, locate, diagnose, fix, validate, and prevent failures.

The system must serve humans, IDEs, CI systems, automated tooling, and AI coding agents.

2. Error categories

MINK distinguishes at least four major categories:

  1. Compile-time errors
  2. Runtime errors
  3. Recoverable application errors
  4. Tooling and environment errors

These categories must not be unnecessarily conflated.

3. Compile-Time errors

Compile-time errors include invalid syntax, type mismatches, invalid imports, unresolved names, invalid generic constraints, exhaustiveness failures, invalid ownership operations, and other statically detectable violations.

The compiler should reject invalid programs before execution whenever the problem can be proven statically.

4. Recoverable errors

Expected application failures should normally be represented explicitly through result/error values rather than exceptions.

Examples include:

  • File not found
  • Network unavailable
  • Invalid user input
  • Authentication failure
  • Database failure
  • API failure
  • Configuration failure

The standard error model must make these failures easy to propagate and handle.

5. Result-Based error handling

MINK should provide a standard Result abstraction representing either success or failure.

Result values must integrate with:

  • Pattern matching
  • Generic types
  • Error propagation
  • Async operations
  • Standard-library APIs
  • Compiler diagnostics

6. Error propagation

MINK should provide concise syntax for propagating recoverable errors through call chains.

Error-aware code should remain readable without requiring repetitive boilerplate at every call site.

The propagation mechanism must preserve the original error context.

7. Error context

Errors should support structured context.

Context may include:

  • Error category
  • Stable error code
  • Human-readable message
  • Source location
  • Operation being performed
  • Relevant values where safe
  • Underlying cause
  • Additional metadata
  • Suggested remediation

8. Error chains

Errors should be able to preserve causal chains.

For example:

Application failure -> database operation failed -> network request failed -> connection timeout

The developer should be able to inspect the root cause without losing higher-level context.

9. Error codes

Stable machine-readable error identifiers should be supported.

Error codes should be suitable for:

  • Programmatic handling
  • Documentation
  • Logging
  • Monitoring
  • IDE integration
  • AI analysis

Human-readable messages must not be treated as stable API identifiers.

10. Exceptions

Exceptions should not be the default mechanism for ordinary recoverable application errors.

An exception mechanism may exist for genuinely exceptional conditions, runtime boundaries, cancellation, or integration with external ecosystems if justified.

The final exception model is an architecture decision.

11. Panic/Fatal conditions

MINK may provide an explicit mechanism for unrecoverable programmer or runtime conditions.

Such failures must produce structured diagnostics rather than silent termination.

Fatal conditions should be distinguishable from ordinary recoverable errors.

12. Diagnostic structure

Every compiler diagnostic should have structured information internally, including:

  • Severity
  • Diagnostic code
  • Primary source span
  • Related source spans
  • Message
  • Explanation
  • Root cause where known
  • Suggested fixes
  • Documentation reference where available

Human-readable output is one presentation of this structured diagnostic model.

13. Severity levels

MINK tooling should support at least:

  • Error
  • Warning
  • Information
  • Hint

Additional internal categories may exist without becoming public language concepts.

14. Source locations

Diagnostics should identify precise source locations.

Where possible, diagnostics should highlight the smallest meaningful span rather than an entire line or file.

Complex diagnostics should be able to reference multiple related source locations.

For example, a type mismatch may identify both the expression receiving a value and the declaration that established the expected type.

16. Explanations

Important errors should explain why the compiler rejected the program rather than only stating what was rejected.

Explanations should remain concise by default while allowing developers to expand deeper context.

17. Suggested fixes

Where a safe correction can be inferred, diagnostics should provide machine-applicable fixes.

Examples include:

  • Add missing import
  • Rename unresolved identifier
  • Add missing match branch
  • Insert explicit conversion
  • Correct argument order
  • Add required type annotation

Automatic fixes must never silently alter program semantics when the compiler cannot establish safety.

18. Error cascades

MINK should minimize misleading cascading diagnostics.

When many errors originate from one root mistake, the compiler should identify the probable root cause and group or suppress dependent diagnostics when doing so improves clarity.

19. Runtime diagnostics

Runtime failures should provide structured information comparable to compile-time diagnostics where practical.

Runtime diagnostics should include:

  • Failure category
  • Error code
  • Message
  • Stack trace where available
  • Causal chain
  • Relevant source locations
  • Context
  • Suggested remediation where possible

20. Stack traces

Runtime stack traces should be readable by humans and consumable by tools.

They should preserve meaningful function, module, source-file, and line information in development builds.

Production builds may use optimized representations while retaining useful debugging information when configured.

21. Debug and release diagnostics

MINK should support configurable diagnostic detail.

Development builds should favor maximum actionable information.

Production builds should balance diagnostics, performance, privacy, binary size, and security.

22. Privacy and security

Error reporting must avoid exposing secrets by default.

Passwords, tokens, cryptographic keys, authentication credentials, and sensitive user data must not automatically appear in diagnostics.

Developers should have explicit mechanisms to mark sensitive values.

23. Logging integration

The standard error model should integrate cleanly with structured logging.

Errors should be representable as structured records without requiring fragile string parsing.

24. IDE/LSP integration

Compiler diagnostics must be directly consumable by IDEs and language servers.

Tooling should support:

  • Inline diagnostics
  • Quick fixes
  • Error navigation
  • Diagnostic filtering
  • Related-location navigation
  • Documentation lookup
  • Automated fixes

25. Machine-Readable diagnostics

MINK tooling must provide a stable machine-readable diagnostic format.

The format should support JSON or another structured representation suitable for IDEs, CI, scripts, and AI agents.

Human-readable terminal output and machine-readable output must originate from the same underlying diagnostic model.

Implementation status (Session 279): mink check --json emits schema version 1 of a JSON report built from the same CheckReport the human renderer uses. The full field-by-field contract, including per-file source attribution, byte-accurate spans, stage names, determinism, and current limitations, is in docs/compiler/DIAGNOSTICS.md. Codes are the stable identifiers required by ยง"Error codes"; their authoritative list is the code() implementation of each error type (src/{lexer,parser,semantics,typecheck,...}/error.rs). E-T44 (CannotInferTypeArguments, added in Session 279) is the most recent addition.

Diagnostics without a real source location (an unreadable file, a directory argument, an I/O failure) are reported with "code": null and "span": null. Inventing a code or a location for them would be a false promise to tools.

26. AI-Native diagnostics

MINK diagnostics should be exceptionally useful to AI coding agents.

An AI-readable diagnostic should expose:

  • Exact failure
  • Root cause
  • Source location
  • Dependency/context chain
  • Expected state
  • Actual state
  • Suggested fixes
  • Relevant documentation identifiers
  • Confidence where root-cause inference is uncertain

The goal is to allow an AI agent to diagnose and repair a failure without scraping human-oriented terminal text.

27. AI error resolution workflow

MINK tooling should eventually support a workflow similar to:

  1. Build
  2. Detect failure
  3. Produce structured diagnostic
  4. Identify root cause
  5. Suggest repair
  6. Apply repair through tooling
  7. Rebuild
  8. Run affected tests
  9. Verify resolution
  10. Report remaining failures

AI assistance must remain optional and must never be required to compile or execute MINK programs.

28. Web and application development

MINK diagnostics should be particularly strong for backend and web application development.

Tooling should eventually help diagnose:

  • HTTP failures
  • Routing problems
  • Serialization errors
  • Database errors
  • Dependency failures
  • Configuration problems
  • Authentication/authorization issues
  • Async failures
  • Network failures

Frameworks may extend the diagnostic model while preserving the core structure.

29. Error documentation

Public error codes and major compiler diagnostics should have searchable documentation.

Documentation should explain the cause, common triggers, fixes, prevention, and relevant language concepts.

30. Testing error paths

MINK tooling should make error-path testing straightforward.

Applications should be able to assert error categories, codes, causes, and structured metadata without depending on fragile human-readable messages.

31. Error handling principle

An error should tell the developer what happened, why it happened, where it happened, how to fix it, and how to prevent it.

32. Open technical decisions

The following must be finalized before architecture freeze:

  • Exact Result syntax
  • Error propagation syntax
  • Exception model
  • Fatal/panic model
  • Diagnostic wire format
  • Diagnostic code namespace
  • Error metadata model
  • Stack-trace representation
  • Logging integration
  • AI diagnostic schema
  • Framework diagnostic extension mechanism

This page is generated from the file in the repository, which is the source of truth. Found a mistake? Open an issue.