fromResult static method
Map a rac_result_t (signed C ABI error code) to an SDKException via
the canonical commons helper rac_result_to_proto_error, deserializing
the returned SDKError proto. Returns null for RAC_SUCCESS (0).
Mirrors Swift's SDKException.from(rcResult:) so the rac_result_t → proto
translation lives in one place (commons) across every SDK instead of
being re-mapped here. Falls back to an ERROR_CODE_UNSPECIFIED envelope
if deserialization fails.
Implementation
static SDKException? fromResult(int code) {
if (code == 0) return null;
final bind = RacNative.bindings.rac_result_to_proto_error;
try {
final proto = DartBridgeProtoUtils.callOut<pb.SDKError>(
invoke: (out) => bind(code, out),
decode: pb.SDKError.fromBuffer,
symbol: 'rac_result_to_proto_error',
);
return SDKException(proto);
} catch (_) {
// Fall through to the generic envelope below.
}
final err = pb.SDKError(
code: pb_enum.ErrorCode.ERROR_CODE_UNSPECIFIED,
category: pb_enum.ErrorCategory.ERROR_CATEGORY_INTERNAL,
message: 'Unknown error code: $code',
cAbiCode: code,
);
return SDKException(err);
}