Skip to content

Return errors rather than panicking for callable APIs #809

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
20 changes: 14 additions & 6 deletions sled-agent/src/sled_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use crate::params::{
use crate::services::ServiceManager;
use crate::storage_manager::StorageManager;
use omicron_common::api::{
internal::nexus::DiskRuntimeState, internal::nexus::InstanceRuntimeState,
internal::nexus::UpdateArtifact,
external::Error as ExternalError, internal::nexus::DiskRuntimeState,
internal::nexus::InstanceRuntimeState, internal::nexus::UpdateArtifact,
};
use slog::Logger;
use std::net::SocketAddr;
Expand Down Expand Up @@ -54,12 +54,20 @@ pub enum Error {

#[error("Error updating: {0}")]
Download(#[from] crate::updates::Error),

#[error("Not yet implemented")]
NotImplemented,
}

impl From<Error> for omicron_common::api::external::Error {
impl From<Error> for ExternalError {
fn from(err: Error) -> Self {
omicron_common::api::external::Error::InternalError {
internal_message: err.to_string(),
match err {
Error::NotImplemented => ExternalError::InternalError {
internal_message: "Method not implemented".to_string(),
},
_ => ExternalError::InternalError {
internal_message: err.to_string(),
},
}
}
}
Expand Down Expand Up @@ -198,7 +206,7 @@ impl SledAgent {
_initial_state: DiskRuntimeState,
_target: DiskStateRequested,
) -> Result<DiskRuntimeState, Error> {
todo!("Disk attachment not yet implemented");
Err(Error::NotImplemented)
}

/// Downloads and applies an artifact.
Expand Down