#[non_exhaustive]pub enum RowError {
ColumnNotFound(String),
#[non_exhaustive] IndexOutOfRange {
index: usize,
len: usize,
},
#[non_exhaustive] TypeConversion {
column: String,
type_code: TypeCode,
source: ConvertError,
},
}Expand description
Errors that can occur when getting a value from a Row.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
ColumnNotFound(String)
The requested column name was not found in the row.
#[non_exhaustive]IndexOutOfRange
The requested column index was out of range.
Fields
This variant is marked as non-exhaustive
#[non_exhaustive]TypeConversion
Failed to convert the column value to the requested type.
Fields
This variant is marked as non-exhaustive
source: ConvertErrorThe underlying conversion error.
Implementations§
Source§impl RowError
impl RowError
Sourcepub fn column_not_found(column: impl Into<String>) -> Self
pub fn column_not_found(column: impl Into<String>) -> Self
Creates a RowError::ColumnNotFound with the requested column name.
§Example
use google_cloud_spanner::error::RowError;
let error = RowError::column_not_found("user_id");
assert_eq!(error.to_string(), "Could not find column: 'user_id'");Sourcepub fn index_out_of_range(index: usize, len: usize) -> Self
pub fn index_out_of_range(index: usize, len: usize) -> Self
Creates a RowError::IndexOutOfRange with the requested index and total column count.
§Example
use google_cloud_spanner::error::RowError;
let error = RowError::index_out_of_range(5, 3);
assert_eq!(error.to_string(), "Column index out of range: 5 (expected < 3)");Sourcepub fn type_conversion(
column: impl Into<String>,
type_code: TypeCode,
source: ConvertError,
) -> Self
pub fn type_conversion( column: impl Into<String>, type_code: TypeCode, source: ConvertError, ) -> Self
Creates a RowError::TypeConversion with the column identifier, type code, and source error.
§Example
use google_cloud_spanner::error::{ConvertError, RowError};
use google_cloud_spanner::types::TypeCode;
let source = ConvertError::type_mismatch(TypeCode::Int64, TypeCode::String);
let error = RowError::type_conversion("age", TypeCode::String, source);
assert_eq!(
error.to_string(),
"Type conversion error for column 'age' (type String): type mismatch, expected Int64, got String"
);Sourcepub fn extract(err: &Error) -> Option<&Self>
pub fn extract(err: &Error) -> Option<&Self>
Extracts a RowError from a google_cloud_spanner::Error, if present.
§Example
let db_client = client.database_client("projects/p/instances/i/databases/d").build().await?;
let transaction = db_client.single_use().build();
let mut result_set = transaction
.execute_query(Statement::builder("SELECT 42 AS id").build())
.await?;
if let Some(row) = result_set.next().await {
let result: Result<i64, _> = row?.get("nonexistent_column");
if let Err(error) = result {
if let Some(row_error) = RowError::extract(&error) {
match row_error {
RowError::ColumnNotFound(column) => println!("Column not found: {column}"),
RowError::IndexOutOfRange { index, len, .. } => {
println!("Index {index} out of range (length {len})");
}
RowError::TypeConversion { column, type_code, source, .. } => {
println!("Conversion error for {column} ({type_code:?}): {source}");
}
_ => {}
}
}
}
}Row operations return Error with a source of RowError when a column lookup
fails, an index is out of bounds, or type conversion fails. This method traverses
the error chain to extract the underlying RowError.
Trait Implementations§
Source§impl Error for RowError
impl Error for RowError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Auto Trait Implementations§
impl !RefUnwindSafe for RowError
impl !UnwindSafe for RowError
impl Forget for RowError
impl Freeze for RowError
impl Move for RowError
impl Send for RowError
impl Sync for RowError
impl Unpin for RowError
impl UnsafeUnpin for RowError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request