Every throwing SDK call throws SDKException. There is no SDKError type.
SDKException
SDKException is a struct wrapping a proto RASDKError. It conforms to Error, LocalizedError,
Sendable, CustomStringConvertible, Equatable, and Hashable.
Branch on category first
RAErrorCategory has a small, stable set of values. RAErrorCode has hundreds. Handle the
category, then drill into specific codes only where you can do something different.
RAErrorCategory cases: .unspecified, .network, .validation, .model, .component, .io,
.auth, .`internal`, .configuration. Note the backticks: internal is a Swift keyword.
Codes worth handling individually
RAErrorCode is generated from the proto, so a switch must be exhaustive: include default or
handle .UNRECOGNIZED.
Codes are grouped by numeric range: 100 to 106 initialization and configuration, 110 to 116 model,
130 to 136 generation, 150 to 161 network, 180 to 193 storage, 220 to 221 hardware, 230 to 236 component state,
250+ validation.
The case is .invalidApiKey, not .invalidAPIKey. Swift protobuf lowercases the acronym.
Cancellation is not a failure
.cancelled and .streamCancelled arrive when the caller cancelled. isExpected on RAErrorCode
marks exactly those two so you can suppress logging. .generationCancelled (code 136) is a distinct
code and is not covered by isExpected.
Validation errors
Validation failures carry the offending field on fieldPath.
Constructing exceptions
You rarely need to, but the factories exist for wrapping your own failures on the same shape:
Or build one directly:
To normalize an arbitrary Error:
SwiftUI
Non-throwing entry points
Not every failure arrives as a thrown exception. loadModel and unloadModel return a result with
a success flag instead:
listModels, queryModels, getModel, and getStorageInfo follow the same pattern.
Errors on the event bus
Errors emitted from background work reach RunAnywhere.events. Subscribe to the error category
rather than filtering the full stream.
RASDKEvent has no .type property. The discriminants are .category (RAEventCategory) and the
.event oneof payload.