google_cloud_bigquery/write/
error.rs1use crate::Error;
16use crate::model::RowError;
17
18#[derive(thiserror::Error, Debug)]
20#[non_exhaustive]
21pub enum AppendError {
22 #[non_exhaustive]
24 #[error("the operation failed. RPC error: {source}")]
25 Rpc {
26 #[from]
28 #[source]
29 source: Error,
30 },
31
32 #[error(
34 "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:?}"
35 )]
36 RowErrors(Vec<RowError>),
37
38 #[error(
40 "the `AppendRows` stream closed unexpectedly and the client library could not recover."
41 )]
42 UnexpectedEndOfStream,
43}
44
45pub(crate) type AppendResult<T> = std::result::Result<T, AppendError>;
46
47#[derive(thiserror::Error, Debug)]
49#[non_exhaustive]
50pub enum AttachError {
51 #[error("stream type mismatch: requested {expected:?}, but matched resource yields {actual:?}")]
53 TypeMismatch {
54 expected: crate::model::write_stream::Type,
56 actual: crate::model::write_stream::Type,
58 },
59
60 #[non_exhaustive]
62 #[error("the operation failed. RPC error: {source}")]
63 Rpc {
64 #[from]
66 #[source]
67 source: Error,
68 },
69}
70
71pub(crate) type AttachResult<T> = std::result::Result<T, AttachError>;
72
73#[cfg(test)]
74mod tests {
75 use super::*;
76 use google_cloud_gax::error::rpc::{Code, Status};
77
78 #[test]
79 fn append_error_rpc_debug() {
80 let e = AppendError::Rpc {
81 source: Error::service(
82 Status::default()
83 .set_code(Code::FailedPrecondition)
84 .set_message("inner fail"),
85 ),
86 };
87 let fmt = format!("{e}");
88 assert!(fmt.contains("operation failed."), "{fmt}");
89 assert!(fmt.contains("inner fail"), "{fmt}");
90 }
91}