Skip to content

[MED] Improve error context - Add file:line information and descriptive error messages #276

@MichaelFisher1997

Description

@MichaelFisher1997

Problem

Many functions in the codebase use Zig's error unions with generic error types, making it difficult to trace the origin of errors. Long try chains can obscure where errors actually occur.

Current State

Example from app.zig:

const rhi = try rhi_vulkan.createRHI(allocator, wm.window, null, ...);
errdefer rhi.deinit();
try rhi.init(allocator, null);

When an error occurs, you only see the error type (e.g., error.OutOfMemory) without context about which specific call failed.

Proposed Solution

Improve error handling in two ways:

Option 1: Rich Error Types

Create error structs with context including file, line, and message.

Option 2: Logging with Context

Add detailed logging at error sites using @src() for file:line info.

Option 3: Zig Error Return Traces

Use @errorReturnTrace() in debug builds to capture stack traces.

Specific Areas to Improve

  • App.init() - Add context for each subsystem initialization
  • World.init() - Distinguish between storage, streamer, renderer init failures
  • ChunkMesh.build() - Report which chunk failed meshing
  • RHI operations - Include resource type and size in errors
  • Shader compilation - Include shader name and error message

Benefits

  • Faster debugging when errors occur
  • Clearer error messages for users
  • Easier to diagnose issues in production

Acceptance Criteria

  • Critical initialization paths have detailed error logging
  • Error messages include file and line information
  • Debug builds include full stack traces
  • Document error handling strategy
  • Tests still pass

Related Files

  • src/game/app.zig
  • src/world/world.zig
  • src/engine/core/log.zig
  • src/engine/graphics/rhi.zig

Estimated Effort

Medium (requires auditing all error paths)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdocumentationImprovements or additions to documentationenhancementNew feature or requesthotfix

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions