AimuxException.fromC constructor

AimuxException.fromC(
  1. AimuxCError e
)

Build the typed subclass from a filled C AimuxCError.

Call only after a fallible FFI return indicated failure. If e.code is AimuxErrorCode.ok (or the message is empty), produces a generic failure with AimuxErrorCode.unknown. Does not free e.message or e.errorValue — the enclosing withAimuxCError does.

Implementation

factory AimuxException.fromC(AimuxCError e) {
  var code = e.code;
  var message = e.message == nullptr ? '' : e.message.toDartString();

  if (code == AimuxErrorCode.ok) {
    code = AimuxErrorCode.unknown;
    if (message.isEmpty) message = 'aimux: operation failed';
  } else if (message.isEmpty) {
    message = 'aimux: ${AimuxErrorCode.name(code)}';
  }

  return AimuxException.fromCode(
    code,
    message,
    status: e.status,
    retryMs: e.retryMs,
    errorValue:
        e.errorValue == nullptr ? null : e.errorValue.toDartString(),
  );
}