freenet-core icon indicating copy to clipboard operation
freenet-core copied to clipboard

Improve client_api::Error enum in stdlib

Open sanity opened this issue 8 months ago • 3 comments

This should be improved, eg. OtherError's parameter should probably be a string rather than a boxed error, why does ConnectionError take a serde value, etc.

#[derive(thiserror::Error, Debug)]
#[non_exhaustive]
pub enum Error {
    #[error(transparent)]
    Deserialization(#[from] bincode::Error),
    #[error("channel closed")]
    ChannelClosed,
    #[cfg(all(any(unix, windows), feature = "net"))]
    #[error(transparent)]
    ConnectionError(#[from] tokio_tungstenite::tungstenite::Error),
    #[cfg(all(target_family = "wasm", feature = "net"))]
    #[error("request error: {0}")]
    ConnectionError(serde_json::Value),
    #[error("connection closed")]
    ConnectionClosed,
    #[error("unhandled error: {0}")]
    OtherError(Box<dyn std::error::Error + Send + Sync>),
}

sanity avatar Mar 22 '25 16:03 sanity

why does ConnectionError take a serde value

cause websys returns jsons as errors basically and is what is being used under wasm target

iduartgomez avatar Mar 23 '25 01:03 iduartgomez

OtherError's parameter should probably be a string rather than a boxed error

Not necesarely since a boxed error contains more information (e.g. possibly backtraces)

iduartgomez avatar Mar 23 '25 01:03 iduartgomez

Ok, will close.

sanity avatar Mar 23 '25 01:03 sanity

🤖 Relabeled for consistency

Applied labels:

  • T-enhancement
  • P-medium
  • E-medium
  • A-developer-xp

Reasoning: The report requests improvements to the client_api::Error enum (types and consistency), which is an enhancement rather than a bug. Changing error variants and their payload types will likely require updating call sites, so it is moderate effort. This primarily affects developer experience and the stdlib API, so A-developer-xp is appropriate.

Previous labels: A-developer-xp,T-enhancement

sanity avatar Oct 27 '25 02:10 sanity