Re: [PR] feat: add a generic error type (datasketches-rust)

2025-12-29 Thread via GitHub


leerho merged PR #47:
URL: https://github.com/apache/datasketches-rust/pull/47


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


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] feat: add a generic error type (datasketches-rust)

2025-12-29 Thread via GitHub


tisonkun commented on PR #47:
URL: https://github.com/apache/datasketches-rust/pull/47#issuecomment-3696821914

   cc @leerho This PR should be mergeable now.


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


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] feat: add a generic error type (datasketches-rust)

2025-12-29 Thread via GitHub


tisonkun commented on code in PR #47:
URL: https://github.com/apache/datasketches-rust/pull/47#discussion_r2650483717


##
datasketches/src/error.rs:
##
@@ -19,31 +19,197 @@
 
 use std::fmt;
 
-/// Errors that can occur during sketch serialization or deserialization
-#[derive(Debug, Clone)]
-pub enum SerdeError {
-/// Insufficient data in buffer
-InsufficientData(String),
-/// Invalid sketch family identifier
-InvalidFamily(String),
-/// Unsupported serialization version
-UnsupportedVersion(String),
-/// Invalid parameter value
-InvalidParameter(String),
-/// Malformed or corrupt sketch data
-MalformedData(String),
-}
-
-impl fmt::Display for SerdeError {
-fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+/// ErrorKind is all kinds of Error of datasketches.
+#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
+#[non_exhaustive]
+pub enum ErrorKind {
+/// The argument provided is invalid.
+InvalidArgument,
+/// The sketch data deserializing is malformed.
+MalformedDeserializeData,
+}
+
+impl ErrorKind {
+/// Convert this error kind instance into static str.
+pub const fn into_static(self) -> &'static str {
 match self {
-SerdeError::InsufficientData(msg) => write!(f, "insufficient data: 
{}", msg),
-SerdeError::InvalidFamily(msg) => write!(f, "invalid family: {}", 
msg),
-SerdeError::UnsupportedVersion(msg) => write!(f, "unsupported 
version: {}", msg),
-SerdeError::InvalidParameter(msg) => write!(f, "invalid parameter: 
{}", msg),
-SerdeError::MalformedData(msg) => write!(f, "malformed data: {}", 
msg),
+ErrorKind::InvalidArgument => "InvalidArgument",
+ErrorKind::MalformedDeserializeData => "MalformedDeserializeData",
 }
 }
 }
 
-impl std::error::Error for SerdeError {}
+impl fmt::Display for ErrorKind {
+fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+write!(f, "{}", self.into_static())
+}
+}
+
+/// Error is the error struct returned by all datasketches functions.
+pub struct Error {
+kind: ErrorKind,
+message: String,
+context: Vec<(&'static str, String)>,
+source: Option,

Review Comment:
   IIRC the auto convesion (From/Into) will have some trouble. I ever try to 
replace `anyhow::Error` with box dyn Error + Send/Sync, but it ruins the 
experience and I remember some compile failure.
   
   However, we don't depend on source error now. So now, I tend to remove this 
feature as well as the `anyhow` dependency. When we need it, we can add it back 
and evaluate the solution at that moment.



##
datasketches/src/error.rs:
##
@@ -19,31 +19,197 @@
 
 use std::fmt;
 
-/// Errors that can occur during sketch serialization or deserialization
-#[derive(Debug, Clone)]
-pub enum SerdeError {
-/// Insufficient data in buffer
-InsufficientData(String),
-/// Invalid sketch family identifier
-InvalidFamily(String),
-/// Unsupported serialization version
-UnsupportedVersion(String),
-/// Invalid parameter value
-InvalidParameter(String),
-/// Malformed or corrupt sketch data
-MalformedData(String),
-}
-
-impl fmt::Display for SerdeError {
-fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+/// ErrorKind is all kinds of Error of datasketches.
+#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
+#[non_exhaustive]
+pub enum ErrorKind {
+/// The argument provided is invalid.
+InvalidArgument,
+/// The sketch data deserializing is malformed.
+MalformedDeserializeData,
+}
+
+impl ErrorKind {
+/// Convert this error kind instance into static str.
+pub const fn into_static(self) -> &'static str {
 match self {
-SerdeError::InsufficientData(msg) => write!(f, "insufficient data: 
{}", msg),
-SerdeError::InvalidFamily(msg) => write!(f, "invalid family: {}", 
msg),
-SerdeError::UnsupportedVersion(msg) => write!(f, "unsupported 
version: {}", msg),
-SerdeError::InvalidParameter(msg) => write!(f, "invalid parameter: 
{}", msg),
-SerdeError::MalformedData(msg) => write!(f, "malformed data: {}", 
msg),
+ErrorKind::InvalidArgument => "InvalidArgument",
+ErrorKind::MalformedDeserializeData => "MalformedDeserializeData",
 }
 }
 }
 
-impl std::error::Error for SerdeError {}
+impl fmt::Display for ErrorKind {
+fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+write!(f, "{}", self.into_static())
+}
+}
+
+/// Error is the error struct returned by all datasketches functions.
+pub struct Error {
+kind: ErrorKind,
+message: String,
+context: Vec<(&'static str, String)>,
+source: Option,

Review Comment:
   IIRC the auto convesion (From/Into) will have some trouble. I ever try to 
replace `anyhow::Error` with box dyn Error + Send/Sync in OpenDAL, but it ruins 
the experi

Re: [PR] feat: add a generic error type (datasketches-rust)

2025-12-29 Thread via GitHub


tisonkun commented on code in PR #47:
URL: https://github.com/apache/datasketches-rust/pull/47#discussion_r2650489287


##
datasketches/src/error.rs:
##
@@ -19,31 +19,197 @@
 
 use std::fmt;
 
-/// Errors that can occur during sketch serialization or deserialization
-#[derive(Debug, Clone)]
-pub enum SerdeError {
-/// Insufficient data in buffer
-InsufficientData(String),
-/// Invalid sketch family identifier
-InvalidFamily(String),
-/// Unsupported serialization version
-UnsupportedVersion(String),
-/// Invalid parameter value
-InvalidParameter(String),
-/// Malformed or corrupt sketch data
-MalformedData(String),
-}
-
-impl fmt::Display for SerdeError {
-fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+/// ErrorKind is all kinds of Error of datasketches.
+#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
+#[non_exhaustive]
+pub enum ErrorKind {
+/// The argument provided is invalid.
+InvalidArgument,
+/// The sketch data deserializing is malformed.
+MalformedDeserializeData,
+}
+
+impl ErrorKind {
+/// Convert this error kind instance into static str.
+pub const fn into_static(self) -> &'static str {
 match self {
-SerdeError::InsufficientData(msg) => write!(f, "insufficient data: 
{}", msg),
-SerdeError::InvalidFamily(msg) => write!(f, "invalid family: {}", 
msg),
-SerdeError::UnsupportedVersion(msg) => write!(f, "unsupported 
version: {}", msg),
-SerdeError::InvalidParameter(msg) => write!(f, "invalid parameter: 
{}", msg),
-SerdeError::MalformedData(msg) => write!(f, "malformed data: {}", 
msg),
+ErrorKind::InvalidArgument => "InvalidArgument",
+ErrorKind::MalformedDeserializeData => "MalformedDeserializeData",
 }
 }
 }
 
-impl std::error::Error for SerdeError {}
+impl fmt::Display for ErrorKind {
+fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+write!(f, "{}", self.into_static())
+}
+}
+
+/// Error is the error struct returned by all datasketches functions.
+pub struct Error {
+kind: ErrorKind,
+message: String,
+context: Vec<(&'static str, String)>,
+source: Option,

Review Comment:
   Updated.



##
datasketches/src/error.rs:
##
@@ -19,31 +19,197 @@
 
 use std::fmt;
 
-/// Errors that can occur during sketch serialization or deserialization
-#[derive(Debug, Clone)]
-pub enum SerdeError {
-/// Insufficient data in buffer
-InsufficientData(String),
-/// Invalid sketch family identifier
-InvalidFamily(String),
-/// Unsupported serialization version
-UnsupportedVersion(String),
-/// Invalid parameter value
-InvalidParameter(String),
-/// Malformed or corrupt sketch data
-MalformedData(String),
-}
-
-impl fmt::Display for SerdeError {
-fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+/// ErrorKind is all kinds of Error of datasketches.
+#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
+#[non_exhaustive]
+pub enum ErrorKind {
+/// The argument provided is invalid.
+InvalidArgument,
+/// The sketch data deserializing is malformed.
+MalformedDeserializeData,

Review Comment:
   Updated.



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


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] feat: add a generic error type (datasketches-rust)

2025-12-29 Thread via GitHub


tisonkun commented on code in PR #47:
URL: https://github.com/apache/datasketches-rust/pull/47#discussion_r2650484211


##
datasketches/src/error.rs:
##
@@ -19,31 +19,197 @@
 
 use std::fmt;
 
-/// Errors that can occur during sketch serialization or deserialization
-#[derive(Debug, Clone)]
-pub enum SerdeError {
-/// Insufficient data in buffer
-InsufficientData(String),
-/// Invalid sketch family identifier
-InvalidFamily(String),
-/// Unsupported serialization version
-UnsupportedVersion(String),
-/// Invalid parameter value
-InvalidParameter(String),
-/// Malformed or corrupt sketch data
-MalformedData(String),
-}
-
-impl fmt::Display for SerdeError {
-fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+/// ErrorKind is all kinds of Error of datasketches.
+#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
+#[non_exhaustive]
+pub enum ErrorKind {
+/// The argument provided is invalid.
+InvalidArgument,
+/// The sketch data deserializing is malformed.
+MalformedDeserializeData,

Review Comment:
   Sounds reasonable. Let me do the rename and see.



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


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] feat: add a generic error type (datasketches-rust)

2025-12-29 Thread via GitHub


tisonkun commented on code in PR #47:
URL: https://github.com/apache/datasketches-rust/pull/47#discussion_r2650483717


##
datasketches/src/error.rs:
##
@@ -19,31 +19,197 @@
 
 use std::fmt;
 
-/// Errors that can occur during sketch serialization or deserialization
-#[derive(Debug, Clone)]
-pub enum SerdeError {
-/// Insufficient data in buffer
-InsufficientData(String),
-/// Invalid sketch family identifier
-InvalidFamily(String),
-/// Unsupported serialization version
-UnsupportedVersion(String),
-/// Invalid parameter value
-InvalidParameter(String),
-/// Malformed or corrupt sketch data
-MalformedData(String),
-}
-
-impl fmt::Display for SerdeError {
-fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+/// ErrorKind is all kinds of Error of datasketches.
+#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
+#[non_exhaustive]
+pub enum ErrorKind {
+/// The argument provided is invalid.
+InvalidArgument,
+/// The sketch data deserializing is malformed.
+MalformedDeserializeData,
+}
+
+impl ErrorKind {
+/// Convert this error kind instance into static str.
+pub const fn into_static(self) -> &'static str {
 match self {
-SerdeError::InsufficientData(msg) => write!(f, "insufficient data: 
{}", msg),
-SerdeError::InvalidFamily(msg) => write!(f, "invalid family: {}", 
msg),
-SerdeError::UnsupportedVersion(msg) => write!(f, "unsupported 
version: {}", msg),
-SerdeError::InvalidParameter(msg) => write!(f, "invalid parameter: 
{}", msg),
-SerdeError::MalformedData(msg) => write!(f, "malformed data: {}", 
msg),
+ErrorKind::InvalidArgument => "InvalidArgument",
+ErrorKind::MalformedDeserializeData => "MalformedDeserializeData",
 }
 }
 }
 
-impl std::error::Error for SerdeError {}
+impl fmt::Display for ErrorKind {
+fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+write!(f, "{}", self.into_static())
+}
+}
+
+/// Error is the error struct returned by all datasketches functions.
+pub struct Error {
+kind: ErrorKind,
+message: String,
+context: Vec<(&'static str, String)>,
+source: Option,

Review Comment:
   IIRC the auto convesion (From/Into) will have some trouble. I ever try to 
replace `anyhow::Error: with box dyn Error + Send/Sync, but it ruins the 
experience and I remember some compile failure.
   
   However, we don't depend on source error now. So now, I tend to remove this 
feature as well as the `anyhow` dependency. When we need it, we can add it back 
and evaluate the solution at that moment.



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


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] feat: add a generic error type (datasketches-rust)

2025-12-29 Thread via GitHub


notfilippo commented on code in PR #47:
URL: https://github.com/apache/datasketches-rust/pull/47#discussion_r2650439694


##
datasketches/src/error.rs:
##
@@ -19,31 +19,197 @@
 
 use std::fmt;
 
-/// Errors that can occur during sketch serialization or deserialization
-#[derive(Debug, Clone)]
-pub enum SerdeError {
-/// Insufficient data in buffer
-InsufficientData(String),
-/// Invalid sketch family identifier
-InvalidFamily(String),
-/// Unsupported serialization version
-UnsupportedVersion(String),
-/// Invalid parameter value
-InvalidParameter(String),
-/// Malformed or corrupt sketch data
-MalformedData(String),
-}
-
-impl fmt::Display for SerdeError {
-fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+/// ErrorKind is all kinds of Error of datasketches.
+#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
+#[non_exhaustive]
+pub enum ErrorKind {
+/// The argument provided is invalid.
+InvalidArgument,
+/// The sketch data deserializing is malformed.
+MalformedDeserializeData,
+}
+
+impl ErrorKind {
+/// Convert this error kind instance into static str.
+pub const fn into_static(self) -> &'static str {
 match self {
-SerdeError::InsufficientData(msg) => write!(f, "insufficient data: 
{}", msg),
-SerdeError::InvalidFamily(msg) => write!(f, "invalid family: {}", 
msg),
-SerdeError::UnsupportedVersion(msg) => write!(f, "unsupported 
version: {}", msg),
-SerdeError::InvalidParameter(msg) => write!(f, "invalid parameter: 
{}", msg),
-SerdeError::MalformedData(msg) => write!(f, "malformed data: {}", 
msg),
+ErrorKind::InvalidArgument => "InvalidArgument",
+ErrorKind::MalformedDeserializeData => "MalformedDeserializeData",
 }
 }
 }
 
-impl std::error::Error for SerdeError {}
+impl fmt::Display for ErrorKind {
+fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+write!(f, "{}", self.into_static())
+}
+}
+
+/// Error is the error struct returned by all datasketches functions.
+pub struct Error {
+kind: ErrorKind,
+message: String,
+context: Vec<(&'static str, String)>,
+source: Option,

Review Comment:
   Can't `source` just be a `Box` + (`Sync + Send` if needed)?



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


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] feat: add a generic error type (datasketches-rust)

2025-12-29 Thread via GitHub


tisonkun commented on code in PR #47:
URL: https://github.com/apache/datasketches-rust/pull/47#discussion_r2650481327


##
Cargo.toml:
##
@@ -32,6 +32,7 @@ rust-version = "1.85.0"
 datasketches = { path = "datasketches" }
 
 # Crates.io dependencies
+anyhow = { version = "1.0.100" }
 byteorder = { version = "1.5.0" }
 clap = { version = "4.5.20", features = ["derive"] }
 googletest = { version = "0.14.2" }

Review Comment:
   Sure. According to [SemVer 
Compatibility](https://doc.rust-lang.org/cargo/reference/semver.html#semver-compatibility)
 "1" means ">=1,<2" and "1.0.100" means ">=1.0.100,<2".
   
   Typically, they will be resolved to the latest 1.x version finally. Unless 
we know a specific version that includes the feature/bugfix we need, `anyhow = 
{ version = "1" }` should be enough.



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


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] feat: add a generic error type (datasketches-rust)

2025-12-29 Thread via GitHub


notfilippo commented on code in PR #47:
URL: https://github.com/apache/datasketches-rust/pull/47#discussion_r2650438334


##
Cargo.toml:
##
@@ -32,6 +32,7 @@ rust-version = "1.85.0"
 datasketches = { path = "datasketches" }
 
 # Crates.io dependencies
+anyhow = { version = "1.0.100" }
 byteorder = { version = "1.5.0" }
 clap = { version = "4.5.20", features = ["derive"] }
 googletest = { version = "0.14.2" }

Review Comment:
   Can we relax dependencies to M.m?



##
datasketches/src/error.rs:
##
@@ -19,31 +19,197 @@
 
 use std::fmt;
 
-/// Errors that can occur during sketch serialization or deserialization
-#[derive(Debug, Clone)]
-pub enum SerdeError {
-/// Insufficient data in buffer
-InsufficientData(String),
-/// Invalid sketch family identifier
-InvalidFamily(String),
-/// Unsupported serialization version
-UnsupportedVersion(String),
-/// Invalid parameter value
-InvalidParameter(String),
-/// Malformed or corrupt sketch data
-MalformedData(String),
-}
-
-impl fmt::Display for SerdeError {
-fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+/// ErrorKind is all kinds of Error of datasketches.
+#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
+#[non_exhaustive]
+pub enum ErrorKind {
+/// The argument provided is invalid.
+InvalidArgument,
+/// The sketch data deserializing is malformed.
+MalformedDeserializeData,
+}
+
+impl ErrorKind {
+/// Convert this error kind instance into static str.
+pub const fn into_static(self) -> &'static str {
 match self {
-SerdeError::InsufficientData(msg) => write!(f, "insufficient data: 
{}", msg),
-SerdeError::InvalidFamily(msg) => write!(f, "invalid family: {}", 
msg),
-SerdeError::UnsupportedVersion(msg) => write!(f, "unsupported 
version: {}", msg),
-SerdeError::InvalidParameter(msg) => write!(f, "invalid parameter: 
{}", msg),
-SerdeError::MalformedData(msg) => write!(f, "malformed data: {}", 
msg),
+ErrorKind::InvalidArgument => "InvalidArgument",
+ErrorKind::MalformedDeserializeData => "MalformedDeserializeData",
 }
 }
 }
 
-impl std::error::Error for SerdeError {}
+impl fmt::Display for ErrorKind {
+fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+write!(f, "{}", self.into_static())
+}
+}
+
+/// Error is the error struct returned by all datasketches functions.
+pub struct Error {
+kind: ErrorKind,
+message: String,
+context: Vec<(&'static str, String)>,
+source: Option,

Review Comment:
   Can't it just be a `Box` + (`Sync + Send` if needed)?



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


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] feat: add a generic error type (datasketches-rust)

2025-12-28 Thread via GitHub


Xuanwo commented on code in PR #47:
URL: https://github.com/apache/datasketches-rust/pull/47#discussion_r2650343829


##
datasketches/src/error.rs:
##
@@ -19,31 +19,197 @@
 
 use std::fmt;
 
-/// Errors that can occur during sketch serialization or deserialization
-#[derive(Debug, Clone)]
-pub enum SerdeError {
-/// Insufficient data in buffer
-InsufficientData(String),
-/// Invalid sketch family identifier
-InvalidFamily(String),
-/// Unsupported serialization version
-UnsupportedVersion(String),
-/// Invalid parameter value
-InvalidParameter(String),
-/// Malformed or corrupt sketch data
-MalformedData(String),
-}
-
-impl fmt::Display for SerdeError {
-fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+/// ErrorKind is all kinds of Error of datasketches.
+#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
+#[non_exhaustive]
+pub enum ErrorKind {
+/// The argument provided is invalid.
+InvalidArgument,
+/// The sketch data deserializing is malformed.
+MalformedDeserializeData,

Review Comment:
   I'm thining if we have an `InvalidData` is enough.



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


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] feat: add a generic error type (datasketches-rust)

2025-12-28 Thread via GitHub


tisonkun commented on code in PR #47:
URL: https://github.com/apache/datasketches-rust/pull/47#discussion_r2650114957


##
datasketches/src/tdigest/sketch.rs:
##
@@ -75,6 +78,32 @@ impl TDigestMut {
 )
 }
 
+/// Creates a tdigest instance with the given value of k.
+///
+/// The panicking version of this method is [`TDigestMut::new`].
+///
+/// # Errors
+///
+/// If k is less than 10, returns [`ErrorKind::InvalidArgument`].
+pub fn try_new(k: u16) -> Result {

Review Comment:
   Demonstrate how a fallible version can be made.
   
   We may later apply the same to `cdf`/`pmf`/`rank`/`quantile`.



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


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] feat: add a generic error type (datasketches-rust)

2025-12-28 Thread via GitHub


tisonkun commented on code in PR #47:
URL: https://github.com/apache/datasketches-rust/pull/47#discussion_r2650113234


##
datasketches/src/error.rs:
##
@@ -19,31 +19,197 @@
 
 use std::fmt;
 
-/// Errors that can occur during sketch serialization or deserialization
-#[derive(Debug, Clone)]
-pub enum SerdeError {
-/// Insufficient data in buffer
-InsufficientData(String),
-/// Invalid sketch family identifier
-InvalidFamily(String),
-/// Unsupported serialization version
-UnsupportedVersion(String),
-/// Invalid parameter value
-InvalidParameter(String),
-/// Malformed or corrupt sketch data
-MalformedData(String),
-}
-
-impl fmt::Display for SerdeError {
-fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+/// ErrorKind is all kinds of Error of datasketches.
+#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
+#[non_exhaustive]
+pub enum ErrorKind {
+/// The argument provided is invalid.
+InvalidArgument,
+/// The sketch data deserializing is malformed.
+MalformedDeserializeData,

Review Comment:
   I'd prefer a better short name but fail to find one.



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


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]