Skip to content

Commit

Permalink
Merge pull request #9 from ccojocar/fix-error-propagation-warnings
Browse files Browse the repository at this point in the history
Fix all compiler warnings related to error propagation
  • Loading branch information
Nercury authored May 8, 2020
2 parents c8a3851 + 3e25cc6 commit 3d12e4c
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 77 deletions.
66 changes: 33 additions & 33 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,19 @@ impl Session {

debug!("getting wsdl from url {:?}", wsdl_url);

let wsdl = try!(wsdl::fetch(&wsdl_url));
let wsdl = wsdl::fetch(&wsdl_url)?;
let mut session = Session {
wsdl,
token: String::new(),
};

let response = try!(session.call(
let response = session.call(
Method::new("login")
.with(Element::node("username").with_text(user))
.with(Element::node("password").with_text(pass))
));
)?;

let token = match try!(response.body.descend(&["loginReturn"])).text {
let token = match response.body.descend(&["loginReturn"])?.text {
Some(token) => token,
_ => return Err(Error::ReceivedNoLoginToken),
};
Expand All @@ -105,11 +105,11 @@ impl Session {
///
/// This is done automatically at the end of Session's lifetime.
pub fn logout(&self) -> Result<bool> {
let response = try!(self.call(
let response = self.call(
Method::new("logout").with(Element::node("token").with_text(self.token.clone()))
));
)?;

Ok(match try!(response.body.descend(&["logoutReturn"])).text {
Ok(match response.body.descend(&["logoutReturn"])?.text {
Some(ref v) if v == "true" => {
debug!("logged out successfully");
true
Expand Down Expand Up @@ -140,15 +140,15 @@ impl Session {
```
*/
pub fn get_space(&self, space_key: &str) -> Result<Space> {
let response = try!(self.call(
let response = self.call(
Method::new("getSpace")
.with(Element::node("token").with_text(self.token.clone()))
.with(Element::node("spaceKey").with_text(space_key))
));
)?;

let element = try!(response.body.descend(&["getSpaceReturn"]));
let element = response.body.descend(&["getSpaceReturn"])?;

Ok(try!(Space::from_element(element)))
Ok(Space::from_element(element)?)
}

/**
Expand All @@ -166,16 +166,16 @@ impl Session {
```
*/
pub fn get_page_by_title(&self, space_key: &str, page_title: &str) -> Result<Page> {
let response = try!(self.call(
let response = self.call(
Method::new("getPage")
.with(Element::node("token").with_text(self.token.clone()))
.with(Element::node("spaceKey").with_text(space_key))
.with(Element::node("pageTitle").with_text(page_title))
));
)?;

let element = try!(response.body.descend(&["getPageReturn"]));
let element = response.body.descend(&["getPageReturn"])?;

Ok(try!(Page::from_element(element)))
Ok(Page::from_element(element)?)
}

/**
Expand All @@ -193,15 +193,15 @@ impl Session {
```
*/
pub fn get_page_by_id(&self, page_id: i64) -> Result<Page> {
let response = try!(self.call(
let response = self.call(
Method::new("getPage")
.with(Element::node("token").with_text(self.token.clone()))
.with(Element::node("pageId").with_text(page_id.to_string()))
));
)?;

let element = try!(response.body.descend(&["getPageReturn"]));
let element = response.body.descend(&["getPageReturn"])?;

Ok(try!(Page::from_element(element)))
Ok(Page::from_element(element)?)
}

/**
Expand Down Expand Up @@ -285,15 +285,15 @@ impl Session {
element_items.push(Element::node("parentId").with_text(parent_id.to_string()));
}

let response = try!(self.call(
let response = self.call(
Method::new("storePage")
.with(Element::node("token").with_text(self.token.clone()))
.with(Element::node("page").with_children(element_items))
));
)?;

let element = try!(response.body.descend(&["storePageReturn"]));
let element = response.body.descend(&["storePageReturn"])?;

Ok(try!(Page::from_element(element)))
Ok(Page::from_element(element)?)
}

/**
Expand Down Expand Up @@ -332,16 +332,16 @@ impl Session {
"false"
}));

let response = try!(self.call(
let response = self.call(
Method::new("updatePage")
.with(Element::node("token").with_text(self.token.clone()))
.with(Element::node("page").with_children(element_items))
.with(Element::node("pageUpdateOptions").with_children(update_options))
));
)?;

let element = try!(response.body.descend(&["updatePageReturn"]));
let element = response.body.descend(&["updatePageReturn"])?;

Ok(try!(Page::from_element(element)))
Ok(Page::from_element(element)?)
}

/**
Expand All @@ -359,18 +359,18 @@ impl Session {
```
*/
pub fn get_children(&self, page_id: i64) -> Result<Vec<PageSummary>> {
let response = try!(self.call(
let response = self.call(
Method::new("getChildren")
.with(Element::node("token").with_text(self.token.clone()))
.with(Element::node("pageId").with_text(page_id.to_string()))
));
)?;

let element = try!(response.body.descend(&["getChildrenReturn"]));
let element = response.body.descend(&["getChildrenReturn"])?;

let mut summaries = vec![];

for element in element.children {
summaries.push(try!(PageSummary::from_element(element)));
summaries.push(PageSummary::from_element(element)?);
}

Ok(summaries)
Expand Down Expand Up @@ -414,11 +414,11 @@ impl Session {
trace!("[method xml] {}", envelope);
}

let http_response = try!(http::soap_action(url, &method.name, &envelope));
let http_response = http::soap_action(url, &method.name, &envelope)?;

trace!("[response xml] {}", http_response.body);

Ok(try!(rpser::Response::from_xml(&http_response.body)))
Ok(rpser::Response::from_xml(&http_response.body)?)
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/rpser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,18 @@ impl Response {
if element.name != "Envelope" {
return Err(RpcError::UnexpectedElement { tag: element.name });
}
element = try!(element.descend(&["Body"]));
element = try!(element.descend_first());
element = element.descend(&["Body"])?;
element = element.descend_first()?;

if element.name == "Fault" {
return Err(RpcError::Fault {
fault_code: try!(element.get_at_path(&["faultcode"]))
fault_code: element.get_at_path(&["faultcode"])?
.text
.unwrap_or_default(),
fault_string: try!(element.get_at_path(&["faultstring"]))
fault_string: element.get_at_path(&["faultstring"])?
.text
.unwrap_or_default(),
fault_detail: Box::new(try!(element.get_at_path(&["detail"]))),
fault_detail: Box::new(element.get_at_path(&["detail"])?),
});
}

Expand Down
8 changes: 4 additions & 4 deletions src/rpser/xml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ impl BuildElement for Element {
}

fn as_int(&self) -> Result<i32, Error> {
let text = try!(get_typed_string(self, "int"));
let text = get_typed_string(self, "int")?;
Ok(match text.parse() {
Ok(ref value) => *value,
Err(e) => {
Expand All @@ -262,7 +262,7 @@ impl BuildElement for Element {
}

fn as_long(&self) -> Result<i64, Error> {
let text = try!(get_typed_string(self, "long"));
let text = get_typed_string(self, "long")?;
Ok(match text.parse() {
Ok(ref value) => *value,
Err(e) => {
Expand All @@ -279,7 +279,7 @@ impl BuildElement for Element {
}

fn as_datetime(&self) -> Result<DateTime<Utc>, Error> {
let text = try!(get_typed_string(self, "dateTime"));
let text = get_typed_string(self, "dateTime")?;
Ok(match text.parse::<DateTime<Utc>>() {
Ok(ref value) => *value,
Err(e) => {
Expand All @@ -292,7 +292,7 @@ impl BuildElement for Element {
}

fn as_boolean(&self) -> Result<bool, Error> {
let text = try!(get_typed_string(self, "boolean"));
let text = get_typed_string(self, "boolean")?;
Ok(text == "true")
}
}
Expand Down
68 changes: 34 additions & 34 deletions src/transforms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,62 +12,62 @@ pub trait FromElement {
impl FromElement for Space {
fn from_element(element: Element) -> Result<Space> {
Ok(Space {
description: try!(element.get_at_path(&["description"])).text,
home_page: try!(element.get_at_path(&["homePage"]).and_then(|e| e.as_long())),
key: try!(element.get_at_path(&["key"]).and_then(|e| e.as_string())),
name: try!(element.get_at_path(&["name"]).and_then(|e| e.as_string())),
space_group: try!(element.get_at_path(&["name"])).text,
space_type: try!(element.get_at_path(&["type"]).and_then(|e| e.as_string())),
url: try!(element.get_at_path(&["url"]).and_then(|e| e.as_string())),
description: element.get_at_path(&["description"])?.text,
home_page: element.get_at_path(&["homePage"]).and_then(|e| e.as_long())?,
key: element.get_at_path(&["key"]).and_then(|e| e.as_string())?,
name: element.get_at_path(&["name"]).and_then(|e| e.as_string())?,
space_group:element.get_at_path(&["name"])?.text,
space_type: element.get_at_path(&["type"]).and_then(|e| e.as_string())?,
url: element.get_at_path(&["url"]).and_then(|e| e.as_string())?,
})
}
}

impl FromElement for Page {
fn from_element(element: Element) -> Result<Page> {
Ok(Page {
id: try!(element.get_at_path(&["id"]).and_then(|e| e.as_long())),
space: try!(element.get_at_path(&["space"]).and_then(|e| e.as_string())),
parent_id: try!(element.get_at_path(&["parentId"]).and_then(|e| e.as_long())),
title: try!(element.get_at_path(&["title"]).and_then(|e| e.as_string())),
url: try!(element.get_at_path(&["url"]).and_then(|e| e.as_string())),
version: try!(element.get_at_path(&["version"]).and_then(|e| e.as_int())),
content: try!(element
id: element.get_at_path(&["id"]).and_then(|e| e.as_long())?,
space: element.get_at_path(&["space"]).and_then(|e| e.as_string())?,
parent_id: element.get_at_path(&["parentId"]).and_then(|e| e.as_long())?,
title: element.get_at_path(&["title"]).and_then(|e| e.as_string())?,
url: element.get_at_path(&["url"]).and_then(|e| e.as_string())?,
version: element.get_at_path(&["version"]).and_then(|e| e.as_int())?,
content: element
.get_at_path(&["content"])
.and_then(|e| e.as_string())),
created: try!(element
.and_then(|e| e.as_string())?,
created: element
.get_at_path(&["created"])
.and_then(|e| e.as_datetime())),
creator: try!(element
.and_then(|e| e.as_datetime())?,
creator: element
.get_at_path(&["creator"])
.and_then(|e| e.as_string())),
modified: try!(element
.and_then(|e| e.as_string())?,
modified: element
.get_at_path(&["modified"])
.and_then(|e| e.as_datetime())),
modifier: try!(element
.and_then(|e| e.as_datetime())?,
modifier: element
.get_at_path(&["modifier"])
.and_then(|e| e.as_string())),
home_page: try!(element
.and_then(|e| e.as_string())?,
home_page: element
.get_at_path(&["homePage"])
.and_then(|e| e.as_boolean())),
content_status: try!(element
.and_then(|e| e.as_boolean())?,
content_status: element
.get_at_path(&["contentStatus"])
.and_then(|e| e.as_string())),
current: try!(element
.and_then(|e| e.as_string())?,
current: element
.get_at_path(&["current"])
.and_then(|e| e.as_boolean())),
.and_then(|e| e.as_boolean())?
})
}
}

impl FromElement for PageSummary {
fn from_element(element: Element) -> Result<PageSummary> {
Ok(PageSummary {
id: try!(element.get_at_path(&["id"]).and_then(|e| e.as_long())),
space: try!(element.get_at_path(&["space"]).and_then(|e| e.as_string())),
parent_id: try!(element.get_at_path(&["parentId"]).and_then(|e| e.as_long())),
title: try!(element.get_at_path(&["title"]).and_then(|e| e.as_string())),
url: try!(element.get_at_path(&["url"]).and_then(|e| e.as_string())),
id: element.get_at_path(&["id"]).and_then(|e| e.as_long())?,
space: element.get_at_path(&["space"]).and_then(|e| e.as_string())?,
parent_id: element.get_at_path(&["parentId"]).and_then(|e| e.as_long())?,
title: element.get_at_path(&["title"]).and_then(|e| e.as_string())?,
url: element.get_at_path(&["url"]).and_then(|e| e.as_string())?,
})
}
}
2 changes: 1 addition & 1 deletion src/wsdl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct Wsdl {

/// Fetch WSDL from specified URL and store results in `Wsdl` structure.
pub fn fetch(url: &str) -> http::Result<Wsdl> {
let response = try!(http::get(&url));
let response = http::get(&url)?;
let mut bytes = response.body.as_bytes();

let mut operations = HashMap::new();
Expand Down

0 comments on commit 3d12e4c

Please sign in to comment.