use crate::Error;
use crate::model::RowError;
#[derive(thiserror::Error, Debug)]
#[non_exhaustive]
pub enum AppendError {
#[non_exhaustive]
#[error("the operation failed. RPC error: {source}")]
Rpc {
#[from]
#[source]
source: Error,
},
#[error(
"the service reports an error for the following rows. No rows in the batch were appended. You can remove the bad rows and retry the request. Rows: {0:?}"
)]
RowErrors(Vec<RowError>),
#[error(
"the `AppendRows` stream closed unexpectedly and the client library could not recover."
)]
UnexpectedEndOfStream,
}
pub(crate) type AppendResult<T> = std::result::Result<T, AppendError>;
#[derive(thiserror::Error, Debug)]
#[non_exhaustive]
pub enum AttachError {
#[error("stream type mismatch: requested {expected:?}, but matched resource yields {actual:?}")]
TypeMismatch {
expected: crate::model::write_stream::Type,
actual: crate::model::write_stream::Type,
},
#[non_exhaustive]
#[error("the operation failed. RPC error: {source}")]
Rpc {
#[from]
#[source]
source: Error,
},
}
pub(crate) type AttachResult<T> = std::result::Result<T, AttachError>;
#[cfg(test)]
mod tests {
use super::*;
use google_cloud_gax::error::rpc::{Code, Status};
#[test]
fn append_error_rpc_debug() {
let e = AppendError::Rpc {
source: Error::service(
Status::default()
.set_code(Code::FailedPrecondition)
.set_message("inner fail"),
),
};
let fmt = format!("{e}");
assert!(fmt.contains("operation failed."), "{fmt}");
assert!(fmt.contains("inner fail"), "{fmt}");
}
}