Error Handling¶
Understanding Kelora's error handling modes and how to diagnose issues.
Processing Modes¶
Kelora offers two error handling modes:
| Mode | Behavior | Use Case |
|---|---|---|
| Resilient (default) | Skip errors, continue processing | Production log analysis, exploratory work |
Strict (--strict) |
Fail-fast on errors | Data validation, CI/CD pipelines |
Resilient Mode¶
Overview¶
In resilient mode (default), Kelora continues processing even when errors occur:
- Parse errors: Skip unparseable lines, continue with next line
- Filter errors: Treat as
false, skip event - Transform errors: Return original event unchanged (atomic rollback)
- Summary: Show error count at end
When to Use¶
- Analyzing messy production logs
- Exploratory data analysis
- Real-time log streaming
- Mixed format log files
Example Behavior¶
Input:
Output:
Summary:
Error Recording¶
Errors are recorded but don't stop processing:
If e.timestamp is missing or invalid:
- Filter evaluates to
false - Event is skipped
- Error is recorded
- Processing continues
Strict Mode¶
Overview¶
In strict mode (--strict), Kelora fails immediately on the first error:
- Parse errors: Show error, abort immediately
- Filter errors: Show error, abort immediately
- Transform errors: Show error, abort immediately
- Exit code: Non-zero on any error
When to Use¶
- Data validation pipelines
- CI/CD quality gates
- Critical processing where partial results aren't acceptable
- Debugging log parsing issues
Example Behavior¶
Input:
Output:
Exit code: 1
Processing stops at the first error. Line 3 is never processed.
Enabling Strict Mode¶
Error Types¶
Parse Errors¶
Occur when input lines can't be parsed in the specified format.
JSON parse error:
Input:
Resilient behavior:
- Line 1: Parsed successfully
- Line 2: Skipped (parse error recorded)
- Line 3: Parsed successfully
Strict behavior:
- Line 1: Parsed successfully
- Line 2: Error shown, processing aborts
- Line 3: Never processed
Filter Errors¶
Occur when --filter expressions fail during evaluation.
Example:
If e.timestamp is missing:
Resilient behavior:
- Filter evaluates to
false - Event is skipped
- Error recorded
Strict behavior:
- Error shown immediately
- Processing aborts
Transform Errors¶
Occur when --exec scripts fail during execution.
Example:
If e.value is not a valid integer:
Resilient behavior:
- Transformation rolled back (atomic)
- Original event returned unchanged
- Error recorded
Strict behavior:
- Error shown immediately
- Processing aborts
Verbose Error Reporting¶
Default Error Reporting¶
By default, errors are collected and summarized at the end:
Summary:
Verbose Mode (--verbose)¶
Show each error immediately as it occurs:
Output:
⚠️ kelora: line 5: exec error - cannot convert 'abc' to integer
result=123
⚠️ kelora: line 12: exec error - cannot convert 'def' to integer
result=456
⚠️ kelora: line 23: exec error - field 'value' not found
result=789
Summary:
Multiple Verbosity Levels¶
-v # Show errors immediately
-vv # Show errors with more context
-vvv # Show errors with full details
Verbose with Strict¶
Combine for immediate errors and fail-fast:
Errors are shown immediately, then processing aborts.
Quiet Modes¶
Graduated Quiet Levels¶
Suppress output for automation:
| Level | Effect |
|---|---|
-q |
Suppress diagnostics (errors, stats, context markers) |
-qq |
Additionally suppress event output (same as -F none) |
-qqq |
Additionally suppress script side effects (print(), eprint()) |
Level 1: Suppress Diagnostics¶
- Errors not shown
- Stats not shown
- Events still output
- Exit code indicates success/failure
Level 2: Suppress Events¶
- Errors not shown
- Events not shown
- Metrics still shown (if
--metrics) - Exit code indicates success/failure
Level 3: Complete Silence¶
- No output at all
- Exit code is only indicator
- Useful for validation pipelines
Exit Codes¶
Kelora uses standard Unix exit codes:
| Code | Meaning |
|---|---|
0 |
Success (no errors) |
1 |
Processing errors (parse/filter/exec errors) |
2 |
Invalid usage (CLI errors, file not found) |
130 |
Interrupted (Ctrl+C) |
141 |
Broken pipe (normal in Unix pipelines) |
Using Exit Codes¶
In shell scripts:
In CI/CD:
With automation:
Atomic Transformations¶
How It Works¶
In resilient mode, --exec scripts execute atomically:
If e.value.to_int() fails:
- Changes to
e.aare rolled back e.bis never sete.cis never set- Original event is returned unchanged
Why Atomic?¶
Prevents partial transformations from corrupting data:
Without atomicity:
// Input
{"value": "invalid"}
// Broken output (partial transformation)
{"value": "invalid", "a": 1} // Missing b and c!
With atomicity:
Multiple --exec Scripts¶
Each --exec script is atomic independently:
If first --exec fails:
- First transformation rolled back
- Second
--execstill runs on original event
If second --exec fails:
- First transformation preserved (it succeeded)
- Second transformation rolled back
Common Error Scenarios¶
Missing Fields¶
Problem:
Some events missing timestamp field.
Solution: Use safe access:
Type Mismatches¶
Problem:
e.value is a string, not a number.
Solution: Use type conversion with defaults:
Invalid Timestamps¶
Problem:
e.timestamp is not a valid timestamp.
Solution: Use safe access:
Array Index Out of Bounds¶
Problem:
e.items is empty or missing.
Solution: Check array length:
Division by Zero¶
Problem:
e.total is zero.
Solution: Add guard:
Debugging Strategies¶
Use Verbose Mode¶
See errors as they happen:
Enable Strict Mode¶
Find first error quickly:
Inspect Problematic Lines¶
Use --take to limit processing:
Process only first 100 lines to find issues faster.
Check Field Existence¶
Verify fields exist before accessing:
Use Type Checking¶
Verify field types before operations:
kelora -j --exec 'if type_of(e.value) != "i64" { eprint("Value is not integer: " + e.value) }' app.log
Validate Input Format¶
Test parsing with strict mode:
No output, but exits with error if parsing fails.
Error Messages¶
Parse Error Format¶
line 42: Line number in inputparse error: Error category- Details: Specific error message
Filter Error Format¶
Exec Error Format¶
Enhanced Error Summaries¶
With --verbose, get example errors:
🔹 Processed 1000 lines, 950 events output, 50 errors
Error examples:
line 42: exec error - cannot convert 'abc' to integer
line 103: exec error - field 'value' not found
line 287: filter error - timestamp is null
Best Practices¶
Use Resilient Mode for Production¶
Production logs are messy - resilient mode handles gracefully:
Use Strict Mode for Validation¶
Validate data quality in pipelines:
Combine Quiet and Exit Codes¶
For automation, use exit codes:
Add Defensive Checks¶
Use safe field access patterns:
Log Errors to File¶
Capture errors for later analysis:
Use Stats for Summary¶
Get error counts without verbose output:
Shows error count in summary.
Parallel Processing¶
Error Handling in Parallel Mode¶
When using --parallel, error handling works the same:
- Errors still recorded per event
- Summary shows total errors across all threads
- Exit code reflects any errors from any thread
Verbose with Parallel¶
Verbose errors are shown immediately, but may be interleaved:
Errors from different threads may appear out of order.
Strict with Parallel¶
First error from any thread aborts all processing:
See Also¶
- Pipeline Model - How error handling fits into processing stages
- Scripting Stages - Error handling in --begin/--exec/--end
- CLI Reference - All error handling flags
- Exit Codes Reference - Complete exit code documentation