Safe API Framework
Layered API framework for safety-related applications (ERTMS RBC reference targeting CENELEC EN 50128 SIL 4)
Loading...
Searching...
No Matches
Status Module - User Guide

What is the Status Module?

  • The Status module provides a unified error/status code system for the entire
  • framework. Every operation returns a sapi_status_t code indicating success
  • or failure reason.
  • Key idea: All functions return the same status codes, making error handling
  • consistent across the entire framework.

Quick Start

Error Handling Patterns

Complete Status Code Reference

Practical Examples

Status Codes to Safety Actions

  • For Safety-Critical Code:
  • c
  • // Vital operations MUST succeed or trigger safe-state
  • sapi_status_t rc = vital_operation();
  • if (rc != SAPI_STATUS_OK) {
  • // ANY failure in vital code is a safety event
  • trigger_safe_state(REASON_VITAL_FAILURE);
  • return rc;
  • }
  • For Non-Vital Code:
  • c
  • // Non-vital operations can fail gracefully
  • sapi_status_t rc = diagnostics_operation();
  • if (rc != SAPI_STATUS_OK) {
  • // Log but don't trigger safe-state
  • log_debug("Diagnostics failed: s", sapi_status_to_string(rc));
  • // Continue normal operation
  • }

Best Practices

  • 1. Always check return codes - Don't ignore status codes
  • c
  • // ❌ BAD: Ignoring return code
  • some_operation();
  • // ✓ GOOD: Checking return code
  • sapi_status_t rc = some_operation();
  • if (rc != SAPI_STATUS_OK) { /* handle error */ }
  • 2. Use early returns - Exit on first error
  • c
  • // ✓ GOOD: Early exit
  • sapi_status_t rc = operation_a();
  • if (rc != SAPI_STATUS_OK) return rc;
  • rc = operation_b();
  • if (rc != SAPI_STATUS_OK) return rc;
  • 3. Log meaningful messages - Include the status code
  • c
  • log_error("Channel read failed: s (code=d)",
  • sapi_status_to_string(rc), rc);
  • 4. Distinguish critical from non-critical
  • c
  • // Critical: trigger safe-state on ANY failure
  • if (vital_rc != SAPI_STATUS_OK) trigger_safe_state();
  • // Non-critical: log and continue
  • if (diag_rc != SAPI_STATUS_OK) log_debug("...");

See Also