mapNativeError function
Map a native error code string to a typed exception.
Implementation
HandbreakException mapNativeError(Map<String, dynamic> map) {
final code = map['code'] as String? ?? 'UNKNOWN';
final msg = map['message'] as String? ?? 'Unknown native error';
final nativeMsg = map['nativeMessage'] as String?;
switch (code) {
case 'INVALID_INPUT':
return InvalidInputException(
msg,
nativeCode: code,
nativeMessage: nativeMsg,
);
case 'UNSUPPORTED_FORMAT':
return UnsupportedFormatException(
msg,
nativeCode: code,
nativeMessage: nativeMsg,
);
case 'CODEC_UNAVAILABLE':
return CodecUnavailableException(
msg,
nativeCode: code,
nativeMessage: nativeMsg,
);
case 'HARDWARE_UNAVAILABLE':
return HardwareEncoderUnavailableException(
msg,
nativeCode: code,
nativeMessage: nativeMsg,
);
case 'OUTPUT_CREATION_FAILED':
return OutputCreationException(
msg,
nativeCode: code,
nativeMessage: nativeMsg,
);
case 'CANCELLED':
return const CancelledCompressionException();
case 'INSUFFICIENT_STORAGE':
return InsufficientStorageException(
msg,
nativeCode: code,
nativeMessage: nativeMsg,
);
case 'OUT_OF_MEMORY':
return OutOfMemoryException(
msg,
nativeCode: code,
nativeMessage: nativeMsg,
);
case 'TIMEOUT':
return CompressionTimeoutException(
msg,
nativeCode: code,
nativeMessage: nativeMsg,
);
default:
return EncodingException(msg, nativeCode: code, nativeMessage: nativeMsg);
}
}