martinzink commented on code in PR #2186:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2186#discussion_r3621132694


##########
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:
   
https://github.com/apache/nifi-minifi-cpp/pull/2186/changes/2355d70f3b28c519c9cb9a2ef73e132ea3234800#diff-f6e0ed2da407a0317d6d217909f48ba767ab0787841075ee0b4cc8c139ee948aR94-R105



-- 
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]

Reply via email to