Error handling module
This module provides error handling:
- Standard exception inheritance from CatchableError
- Simple, focused error types
- Minimal overhead and complexity
Types
BufferError = object of IndexDefect
- Buffer access or manipulation errors
EventError = object of CatchableError
- Event handling errors
LayoutError = object of ValueError
- Layout constraint resolution errors
RenderError = object of CatchableError
- Rendering pipeline errors
TerminalError = object of CatchableError
- Terminal operation failures (ANSI codes, raw mode, etc.)
Procs
proc newBufferError(msg: string): ref BufferError {....raises: [], tags: [], forbids: [].}
- Create a buffer error
proc newEventError(msg: string): ref EventError {....raises: [], tags: [], forbids: [].}
- Create an event error
proc newLayoutError(msg: string): ref LayoutError {....raises: [], tags: [], forbids: [].}
- Create a layout error
proc newRenderError(msg: string): ref RenderError {....raises: [], tags: [], forbids: [].}
- Create a render error
proc newTerminalError(msg: string): ref TerminalError {....raises: [], tags: [], forbids: [].}
- Create a terminal error
proc tryRecover[T](operation: proc (): T; fallback: T): T
- Try an operation and return fallback on error
proc withContext(msg: string; context: string): string {....raises: [], tags: [], forbids: [].}
- Add context to an error message
Templates
template checkSystemCall(call: untyped; errorMsg: string): untyped
- Check system call return value and raise OSError on failure
template checkSystemCallVoid(call: untyped; errorMsg: string): untyped
- Check system call return value for void functions
template debugLog(msg: string)
template ensure(condition: bool; errorMsg: string): untyped
- Ensure condition is true or raise ValueError
template ensureNotNil[T](value: T; errorMsg: string): T
- Ensure value is not nil and return it
template tryIO(body: untyped): untyped
- Simple I/O wrapper that re-raises as IOError if needed
template withErrorContext(context: string; body: untyped): untyped
- Add context to any errors raised in body
template withResource(resource: untyped; cleanup: untyped; body: untyped): untyped
- Execute body with resource, ensuring cleanup on error