Skip to main content

Error Reporting

HIL includes a centralized error reporting system that collects, categorizes, and tracks errors from all connected devices and software components (Musa, 1999).

Error Reporting Architecture​

Error Types​

TypeDescriptionExample
compileSyntax or parse errorMissing parenthesis, unknown operator
runtimeExecution errorDivision by zero, stack overflow
hardwareHardware communication errorSerial timeout, CRC mismatch
networkNetwork/IoT errorMQTT disconnect, HTTP timeout
packagePackage loading errorModule not found, version conflict

Error Object Structure​

{
"id": "err-001",
"timestamp": "2026-01-15T10:30:00Z",
"error_type": "runtime",
"message": "Stack overflow in recursive function",
"device_id": "hil-device-001",
"context": {
"expression": "(FACT 100000)",
"line": 5,
"function": "FACT"
},
"resolved": false,
"resolution": null
}

Reporting Errors via API​

Report an Error​

curl -X POST http://localhost:3002/api/errors \
-H "Content-Type: application/json" \
-d '{
"device_id": "hil-device-001",
"error_type": "runtime",
"message": "ADC overflow on pin A0"
}'

Query Errors​

# Get all errors
curl http://localhost:3002/api/errors

# Response:
{
"errors": [
{
"id": "err-001",
"timestamp": "2026-01-15T10:30:00Z",
"error_type": "runtime",
"message": "ADC overflow on pin A0",
"device_id": "hil-device-001",
"resolved": false
}
],
"total": 1
}

Get Error Statistics​

curl http://localhost:3002/api/errors/stats

# Response:
{
"total": 15,
"byType": {
"compile": 3,
"runtime": 8,
"hardware": 2,
"network": 1,
"package": 1
},
"byDevice": {
"hil-device-001": 10,
"hil-device-002": 5
},
"byHour": {
"2026-01-15T10": 5,
"2026-01-15T11": 10
}
}

Error Handling in HIL LISP​

Try-Catch Pattern​

HIL LISP handles errors gracefully in the REPL evaluator. The DO block stops execution on error, and the error is logged:

; Division by zero is safe (returns 0)
(/ 10 0) ; 0

; Stack overflow is caught
(DEFUN INFINITE () (INFINITE))
(INFINITE) ; Error: stack overflow

Defensive Programming​

Use IF to validate inputs before operations:

; Safe division
(DEFUN SAFE-DIV (a b)
(IF (== b 0) 0 (/ a b)))

; Safe sensor read with validation
(DEFUN SAFE-READ (pin)
(DO
(SET val (READ A pin))
(IF (AND (>= val 0) (<= val 1023)) val 0)))

Error Recovery in Loops​

; Monitor with error recovery
(SET error-count 0)
(WHILE (< error-count 5)
(DO
(SET temp (READ A 0))
(IF (OR (< temp 0) (> temp 1023))
(DO
(SET error-count (+ error-count 1))
(LOG "ADC error #" error-count))
(DO
(SET error-count 0)
(LOG "Temperature: " (/ temp 4) "C")))
(DELAY 1000)))

Error Severity​

SeverityDescriptionTypical Type
HighSystem-critical failurecompile, hardware
MediumRecoverable errorruntime
LowInformationalnetwork, package

Error Resolution​

Errors can be marked as resolved through the API or admin panel:

# Mark error as resolved
curl -X PUT http://localhost:3002/api/errors/err-001 \
-H "Content-Type: application/json" \
-d '{"resolved": true, "resolution": "Replaced sensor module"}'

Diagnostics​

The system provides diagnostic information for debugging:


References

Musa, J. D. (1999). Software reliability engineering. McGraw-Hill.