Skip to content

Commit

Permalink
one more error cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
smklein committed Dec 1, 2023
1 parent 246ac8a commit d6f7692
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 18 deletions.
24 changes: 6 additions & 18 deletions nexus/db-queries/src/db/datastore/switch_port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::db::datastore::address_lot::{
};
use crate::db::datastore::UpdatePrecondition;
use crate::db::error::public_error_from_diesel;
use crate::db::error::retryable;
use crate::db::error::ErrorHandler;
use crate::db::model::{
LldpServiceConfig, Name, SwitchInterfaceConfig, SwitchPort,
Expand All @@ -22,7 +21,6 @@ use crate::db::model::{
use crate::db::pagination::paginated;
use crate::transaction_retry::OptionalError;
use async_bb8_diesel::AsyncRunQueryDsl;
use diesel::result::Error as DieselError;
use diesel::{
CombineDsl, ExpressionMethods, JoinOnDsl, NullableExpressionMethods,
QueryDsl, SelectableHelper,
Expand All @@ -35,7 +33,6 @@ use omicron_common::api::external::{
};
use ref_cast::RefCast;
use serde::{Deserialize, Serialize};
use std::sync::{Arc, OnceLock};
use uuid::Uuid;

#[derive(Clone, Debug, Deserialize, Serialize)]
Expand Down Expand Up @@ -863,7 +860,7 @@ impl DataStore {
RackNotFound,
}

let err = Arc::new(OnceLock::new());
let err = OptionalError::new();

let conn = self.pool_connection_authorized(opctx).await?;
let switch_port = SwitchPort::new(
Expand All @@ -888,19 +885,10 @@ impl DataStore {
.first_async::<Uuid>(&conn)
.await
.map_err(|e| {
// TODO:
// IF retryable
// e
// OTHERWISE
// set a custom error
// e: RollbackTransaction

if retryable(&e) {
return e;
}
err.set(SwitchPortCreateError::RackNotFound)
.unwrap();
DieselError::RollbackTransaction
err.bail_retryable_or(
e,
SwitchPortCreateError::RackNotFound,
)
})?;

// insert switch port
Expand All @@ -917,7 +905,7 @@ impl DataStore {
})
.await
.map_err(|e| {
if let Some(err) = err.get() {
if let Some(err) = err.take() {
match err {
SwitchPortCreateError::RackNotFound => {
Error::invalid_request("rack not found")
Expand Down
41 changes: 41 additions & 0 deletions nexus/preprocessed_configs/config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!-- This file was generated automatically.
Do not edit it: it is likely to be discarded and generated again before it's read next time.
Files used to generate this file:
config.xml -->

<!-- Config that is used when server is run without config file. --><clickhouse>
<logger>
<level>trace</level>
<console>true</console>
</logger>

<http_port>8123</http_port>
<tcp_port>9000</tcp_port>
<mysql_port>9004</mysql_port>

<path>./</path>

<mlock_executable>true</mlock_executable>

<users>
<default>
<password/>

<networks>
<ip>::/0</ip>
</networks>

<profile>default</profile>
<quota>default</quota>
<access_management>1</access_management>
</default>
</users>

<profiles>
<default/>
</profiles>

<quotas>
<default/>
</quotas>
</clickhouse>

0 comments on commit d6f7692

Please sign in to comment.