yoshidan / google-cloud-rust

Google Cloud Client Libraries for Rust.
MIT License
222 stars 80 forks source link

Implement BQ specific error enum #179

Open ragyabraham opened 1 year ago

ragyabraham commented 1 year ago

Rather than using a generic Error type would be helpful to implement a BQError enum similar to the below from https://github.com/lquerel/gcp-bigquery-client/blob/main/src/error.rs

pub enum BQError {
    #[error("Invalid service account key (error: {0})")]
    InvalidServiceAccountKey(#[from] std::io::Error),

    #[error("Invalid service account authenticator (error: {0})")]
    InvalidServiceAccountAuthenticator(std::io::Error),

    #[error("Invalid installed flow authenticator (error: {0})")]
    InvalidInstalledFlowAuthenticator(std::io::Error),

    #[error("Invalid installed application default credentials authenticator (error: {0})")]
    InvalidApplicationDefaultCredentialsAuthenticator(std::io::Error),

    #[error("Invalid authorized user authenticator (error: {0})")]
    InvalidAuthorizedUserAuthenticator(std::io::Error),

    #[error("Authentication error (error: {0})")]
    AuthError(#[from] yup_oauth2::error::AuthError),

    #[error("Authentication error (error: {0})")]
    YupAuthError(#[from] yup_oauth2::Error),

    #[error("No token")]
    NoToken,

    #[error("Request error (error: {0})")]
    RequestError(#[from] reqwest::Error),

    #[error("Response error (error: {error:?})")]
    ResponseError { error: ResponseError },

    #[error("No data available. The result set is positioned before the first or after the last row. Try to call the method next on your result set.")]
    NoDataAvailable,

    #[error("Invalid column index (col_index: {col_index})")]
    InvalidColumnIndex { col_index: usize },

    #[error("Invalid column name (col_name: {col_name})")]
    InvalidColumnName { col_name: String },

    #[error("Invalid column type (col_index: {col_index}, col_type: {col_type}, type_requested: {type_requested})")]
    InvalidColumnType {
        col_index: usize,
        col_type: String,
        type_requested: String,
    },

    #[error("Json serialization error (error: {0})")]
    SerializationError(#[from] serde_json::Error),
}
yoshidan commented 1 year ago

We do not use generic std::error::Error but rather separate errors for each method. For example https://github.com/yoshidan/google-cloud-rust/blob/2d6c3a70a87a73d15a5e621a3554bc359a53e4ed/bigquery/src/query.rs#L110

Which interface do you want me to fix, do you want me to not use transparent, or do you want me to use the same interface as the other?