Skip to content

Commit

Permalink
Update iotedged to return image pull failed message (#414)
Browse files Browse the repository at this point in the history
* Output more details when image pull error for invalid image name, invalid image host and unauthentication for image pull.
* Add new tests for image pull scenarios.
* Manually ran E2E tests to ensure details error message is updated in Edge Agent module twin.
  • Loading branch information
philipktlin authored Oct 15, 2018
1 parent 33fcc81 commit 9f500e4
Show file tree
Hide file tree
Showing 3 changed files with 373 additions and 54 deletions.
52 changes: 39 additions & 13 deletions edgelet/edgelet-docker/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use hyper::{Error as HyperError, StatusCode};
use serde_json;
use url::ParseError;

use docker::apis::Error as DockerError;
use docker::apis::{ApiError as DockerApiError, Error as DockerError};
use edgelet_core::{Error as CoreError, ErrorKind as CoreErrorKind};
use edgelet_http::Error as HttpError;
use edgelet_utils::Error as UtilsError;
Expand All @@ -20,6 +20,26 @@ pub struct Error {
inner: Context<ErrorKind>,
}

fn get_message(
error: DockerApiError<serde_json::Value>,
) -> ::std::result::Result<String, DockerApiError<serde_json::Value>> {
let DockerApiError { code, content } = error;

match content {
Some(serde_json::Value::Object(props)) => {
if let serde_json::Value::String(message) = &props["message"] {
return Ok(message.clone());
}

Err(DockerApiError {
code,
content: Some(serde_json::Value::Object(props)),
})
}
_ => Err(DockerApiError { code, content }),
}
}

#[derive(Debug, Fail)]
pub enum ErrorKind {
#[fail(display = "Invalid docker URI - {}", _0)]
Expand All @@ -34,14 +54,16 @@ pub enum ErrorKind {
Transport,
#[fail(display = "Invalid URL")]
UrlParse,
#[fail(display = "Not found")]
NotFound,
#[fail(display = "{}", _0)]
NotFound(String),
#[fail(display = "Conflict with current operation")]
Conflict,
#[fail(display = "Container already in this state")]
NotModified,
#[fail(display = "Container runtime error")]
Docker,
#[fail(display = "{}", _0)]
FormattedDockerRuntime(String),
#[fail(display = "Container runtime error - {:?}", _0)]
DockerRuntime(DockerError<serde_json::Value>),
#[fail(display = "Core error")]
Expand Down Expand Up @@ -127,16 +149,20 @@ impl From<DockerError<serde_json::Value>> for Error {
DockerError::Serde(error) => Error {
inner: Error::from(error).context(ErrorKind::Docker),
},
DockerError::ApiError(ref error) if error.code == StatusCode::NOT_FOUND => {
Error::from(ErrorKind::NotFound)
}
DockerError::ApiError(ref error) if error.code == StatusCode::CONFLICT => {
Error::from(ErrorKind::Conflict)
}
DockerError::ApiError(ref error) if error.code == StatusCode::NOT_MODIFIED => {
Error::from(ErrorKind::NotModified)
}
_ => Error::from(ErrorKind::DockerRuntime(err)),
DockerError::ApiError(error) => match error.code {
StatusCode::NOT_FOUND => get_message(error)
.map(|message| Error::from(ErrorKind::NotFound(message)))
.unwrap_or_else(|e| {
Error::from(ErrorKind::DockerRuntime(DockerError::ApiError(e)))
}),
StatusCode::CONFLICT => Error::from(ErrorKind::Conflict),
StatusCode::NOT_MODIFIED => Error::from(ErrorKind::NotModified),
_ => get_message(error)
.map(|message| Error::from(ErrorKind::FormattedDockerRuntime(message)))
.unwrap_or_else(|e| {
Error::from(ErrorKind::DockerRuntime(DockerError::ApiError(e)))
}),
},
}
}
}
Expand Down
Loading

0 comments on commit 9f500e4

Please sign in to comment.