szaszm commented on code in PR #2186:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2186#discussion_r3624158320
##########
minifi_rust/minifi_native/src/api/errors.rs:
##########
@@ -0,0 +1,129 @@
+use minifi_native_sys::minifi_status;
+use std::borrow::Cow;
+use std::ffi::NulError;
+use std::fmt;
+use std::num::{NonZeroU32, ParseIntError};
+use std::str::ParseBoolError;
+
+#[derive(Debug, Clone)]
+pub enum ParseError {
+ Strum(strum::ParseError),
+ Bool(ParseBoolError),
+ Int(ParseIntError),
+ Duration(humantime::DurationError),
+ Size(byte_unit::ParseError),
+ Nul(NulError),
+ Other,
+}
+
+#[derive(Debug)]
+pub enum MinifiError {
+ UnknownError,
+ StatusError((Cow<'static, str>, NonZeroU32)),
+ MissingRequiredProperty(Cow<'static, str>),
+ ControllerServiceError(Cow<'static, str>),
+ ValidationError(Cow<'static, str>),
+ ScheduleError(Cow<'static, str>),
+ TriggerError(Cow<'static, str>),
+ Parse(ParseError),
+ MissingFlowFileError,
+ IoError(std::io::Error),
+}
+
+impl From<std::io::Error> for MinifiError {
+ fn from(error: std::io::Error) -> Self {
+ MinifiError::IoError(error)
+ }
+}
+
+impl From<strum::ParseError> for MinifiError {
+ fn from(err: strum::ParseError) -> Self {
+ MinifiError::Parse(ParseError::Strum(err))
+ }
+}
+
+impl From<ParseBoolError> for MinifiError {
+ fn from(err: ParseBoolError) -> Self {
+ MinifiError::Parse(ParseError::Bool(err))
+ }
+}
+
+impl From<ParseIntError> for MinifiError {
+ fn from(err: ParseIntError) -> Self {
+ MinifiError::Parse(ParseError::Int(err))
+ }
+}
+
+impl From<humantime::DurationError> for MinifiError {
+ fn from(err: humantime::DurationError) -> Self {
+ MinifiError::Parse(ParseError::Duration(err))
+ }
+}
+
+impl From<byte_unit::ParseError> for MinifiError {
+ fn from(err: byte_unit::ParseError) -> Self {
+ MinifiError::Parse(ParseError::Size(err))
+ }
+}
+
+impl From<NulError> for MinifiError {
+ fn from(err: NulError) -> Self {
+ MinifiError::Parse(ParseError::Nul(err))
+ }
+}
+
+impl MinifiError {
+ pub(crate) fn to_status(&self) -> minifi_status {
+ // TODO expand this
+ minifi_native_sys::minifi_status_MINIFI_STATUS_UNKNOWN_ERROR
+ }
Review Comment:
MissingRequiredProperty could be mapped to MINIFI_STATUS_PROPERTY_NOT_SET,
StatusError seems like a generic catchall that could be separated to
multiple error types,
ControllerServiceError seems to be unused,
ParseError could be mapped to ValidationError too maybe?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]