Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions src/bigquery/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@ serde_json.workspace = true
google-cloud-auth = { workspace = true }
google-cloud-gax.workspace = true
google-cloud-bigquery-v2 = { workspace = true }
wkt = { workspace = true }
thiserror.workspace = true
wkt.workspace = true
gaxi = { workspace = true, features = ["_internal-common", "_internal-grpc-client", "_internal-http-client"] }

[dev-dependencies]
anyhow.workspace = true
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }

[features]
default = ["default-rustls-provider"]
# Enabled by default. Use the default rustls crypto provider ([aws-lc-rs]) for
Expand All @@ -42,9 +47,5 @@ default = ["default-rustls-provider"]
# default and call `rustls::CryptoProvider::install_default()`.
default-rustls-provider = ["gaxi/_default-rustls-provider"]

[dev-dependencies]
anyhow.workspace = true
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }

[lints]
workspace = true
85 changes: 85 additions & 0 deletions src/bigquery/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! Custom errors for the Cloud BigQuery query client.

use google_cloud_bigquery_v2::model::ErrorProto;
use google_cloud_gax::error::Error;

/// Errors that can occur during query configuration, execution, or polling.
#[derive(thiserror::Error, Debug)]
#[non_exhaustive]
pub enum QueryError {
/// The project ID was not provided or could not be determined.
#[error("no project ID was provided")]
MissingProjectId,

/// Only query jobs are supported by this client.
#[error("only query jobs are supported")]
UnsupportedJobType,
Comment thread
dbolduc marked this conversation as resolved.

/// The query job failed on the BigQuery service side.
/// Includes the list of error protocols returned by the service.
#[error("query job failed: {errors:?}")]
JobFailed {
/// The list of all errors associated with the job.
errors: Vec<ErrorProto>,
},

/// The underlying RPC failed.
#[non_exhaustive]
#[error("the operation failed. RPC error: {source}")]
Rpc {
/// The error returned by the service for the request.
#[source]
source: Error,
},
Comment thread
alvarowolfx marked this conversation as resolved.
}

#[cfg(test)]
mod tests {
use super::*;
use google_cloud_gax::error::rpc::{Code, Status};

#[test]
fn test_job_failed_display() {
let err = QueryError::JobFailed {
errors: vec![
ErrorProto::new()
.set_reason("invalidQuery")
.set_message("Syntax error: Unexpected end of input"),
],
};
assert!(err.to_string().contains("query job failed:"));
assert!(err.to_string().contains("invalidQuery"));
assert!(
err.to_string()
.contains("Syntax error: Unexpected end of input")
);
}

#[test]
fn test_rpc_display() {
let status = Status::default()
.set_code(Code::InvalidArgument)
.set_message("simulated bad request");
let err = QueryError::Rpc {
source: Error::service(status),
};
assert_eq!(
err.to_string(),
"the operation failed. RPC error: the service reports an error with code INVALID_ARGUMENT described as: simulated bad request"
);
}
}
1 change: 1 addition & 0 deletions src/bigquery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

pub use google_cloud_gax::Result;
pub use google_cloud_gax::error::Error;
pub mod error;

pub(crate) use google_cloud_gax::client_builder::Result as ClientBuilderResult;

Expand Down
Loading