Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

volume_repair_insert_in_txn should return its own error #7275

Open
jmpesp opened this issue Dec 18, 2024 · 0 comments
Open

volume_repair_insert_in_txn should return its own error #7275

jmpesp opened this issue Dec 18, 2024 · 0 comments

Comments

@jmpesp
Copy link
Contributor

jmpesp commented Dec 18, 2024

This issue tracks a suggestion during the review of #7046:

If possible it might be nice to have volume_repair_insert_in_txn return its own error enum so that we're not relying on it returning this specific message appearing in this error.

Something like:

diff --git a/nexus/db-queries/src/db/datastore/volume_repair.rs b/nexus/db-queries/src/db/datastore/volume_repair.rs
index 598d9d77a..a910a12ef 100644
--- a/nexus/db-queries/src/db/datastore/volume_repair.rs
+++ b/nexus/db-queries/src/db/datastore/volume_repair.rs
@@ -20,6 +20,30 @@ use diesel::result::Error as DieselError;
 use omicron_common::api::external::Error;
 use uuid::Uuid;
 
+pub enum VolumeRepairInsertError {
+    /// Another lock exists for this Volume
+    Conflict,
+
+    /// Volume was hard-deleted or never existed
+    VolumeNotFound { volume_id },
+}
+
+impl VolumeRepairInsertError {
+    pub fn into_external_error(self) -> Error {
+        match self {
+            Self::Conflict => {
+                Error::conflict("volume repair lock")
+            }
+
+            Self::VolumeNotFound { volume_id } => {
+                Error::invalid_request(format!(
+                    "cannot create record: volume {volume_id} does not exist"
+                ))
+            }
+        }
+    }
+}
+
 impl DataStore {
     /// Insert a volume repair record, taking a "lock" on the volume pointed to
     /// by volume id with some repair id.

with the required propagation of this enum up from functions that call it, so that those callers can decide what to do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant