Skip to content

Commit

Permalink
Handle unwraps in execute_query from feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
codedmart committed Dec 11, 2024
1 parent 31e820d commit 02c5e35
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
3 changes: 3 additions & 0 deletions crates/configuration/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ pub enum Error {
#[error("JSON deserialization error: {0}")]
JsonDeserializationError(String),

#[error("Failed to execute introspection query: {0}")]
IntrospectionQueryExecutionError(String),

// error while parsing stored procedure introspection
#[error("Error parsing stored procedure introspection: {0}")]
StoredProcedureIntrospectionError(serde_json::Error),
Expand Down
9 changes: 6 additions & 3 deletions crates/configuration/src/version1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ async fn configure_stored_procedures(
let mut stored_procs_query = SQL::new();
RawSql::RawText(STORED_PROCS_CONFIGURATION_QUERY.to_string()).to_sql(&mut stored_procs_query);
let mut stored_procs_rows = Vec::new();
execute_query(&mut connection, &stored_procs_query, &BTreeMap::new(), &mut stored_procs_rows).await.unwrap();
execute_query(&mut connection, &stored_procs_query, &BTreeMap::new(), &mut stored_procs_rows).await
.map_err(|e| Error::IntrospectionQueryExecutionError(format!("{:?}", e)))?;
let introspected_stored_procedures: Vec<introspection::IntrospectStoredProcedure> = serde_json::from_slice(&stored_procs_rows)
.map_err(|e| Error::JsonDeserializationError(e.to_string()))?;
let new_stored_procedures = get_stored_procedures(introspected_stored_procedures);
Expand Down Expand Up @@ -230,15 +231,17 @@ pub async fn configure(
let mut table_query = SQL::new();
RawSql::RawText(TABLE_CONFIGURATION_QUERY.to_string()).to_sql(&mut table_query);
let mut table_rows = Vec::new();

Check warning on line 233 in crates/configuration/src/version1.rs

View workflow job for this annotation

GitHub Actions / cargo fmt

Diff in /home/runner/work/ndc-sqlserver/ndc-sqlserver/crates/configuration/src/version1.rs
execute_query(&mut connection, &table_query, &BTreeMap::new(), &mut table_rows).await.unwrap();
execute_query(&mut connection, &table_query, &BTreeMap::new(), &mut table_rows).await
.map_err(|e| Error::IntrospectionQueryExecutionError(format!("{:?}", e)))?;
let tables: Vec<introspection::IntrospectionTable> = serde_json::from_slice(&table_rows)
.map_err(|e| Error::JsonDeserializationError(e.to_string()))?;

// Let's do some types introspection
let mut types_query = SQL::new();
RawSql::RawText(TYPES_QUERY.to_string()).to_sql(&mut types_query);
let mut types_rows = Vec::new();

Check warning on line 242 in crates/configuration/src/version1.rs

View workflow job for this annotation

GitHub Actions / cargo fmt

Diff in /home/runner/work/ndc-sqlserver/ndc-sqlserver/crates/configuration/src/version1.rs
execute_query(&mut connection, &types_query, &BTreeMap::new(), &mut types_rows).await.unwrap();
execute_query(&mut connection, &types_query, &BTreeMap::new(), &mut types_rows).await
.map_err(|e| Error::IntrospectionQueryExecutionError(format!("{:?}", e)))?;
let type_names: Vec<TypeItem> = serde_json::from_slice(&types_rows)
.map_err(|e| Error::JsonDeserializationError(e.to_string()))?;

Expand Down
6 changes: 6 additions & 0 deletions crates/ndc-sqlserver/src/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ impl<Env: Environment + Send + Sync> connector::ConnectorSetup for SQLServerSetu
inner.to_string(),
))
}
configuration::Error::IntrospectionQueryExecutionError(inner) => {
connector::ParseError::from(std::io::Error::new(
std::io::ErrorKind::Other,
inner.to_string(),
))
}
configuration::Error::StoredProcedureIntrospectionError(inner) => {
connector::ParseError::from(std::io::Error::new(
std::io::ErrorKind::Other,
Expand Down

0 comments on commit 02c5e35

Please sign in to comment.