Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
argo
cuttr
Commits
2ea286a9
Commit
2ea286a9
authored
Oct 02, 2018
by
Alexis Janon
Browse files
Second part of error handling refactor
parent
a3510896
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/configuration/mod.rs
View file @
2ea286a9
...
...
@@ -11,11 +11,8 @@ pub struct SysConf {
// TODO: use the same controller as in main?
pub
fn
get_configuration
()
->
Result
<
SysConf
>
{
Ok
(
SysConf
{
controllers
:
get_sys_fs_controllers
()
.map_err
(|
err
|
{
Error
::
from
(
format!
(
"Could not retrieve controllers: {}"
,
err
.to_string
()
))
})
?
,
controllers
:
get_sys_fs_controllers
()
.map_err
(
Error
::
from
)
.map_err
(|
err
|
err
.prepend
(
"Could not retrieve controllers"
))
?
,
})
}
src/show/mod.rs
View file @
2ea286a9
...
...
@@ -6,44 +6,29 @@ use error::*;
use
serde_json
;
pub
fn
configuration
()
->
Result
<
String
>
{
let
conf
=
configuration
::
get_configuration
()
.map_err
(|
err
|
{
Error
::
from
(
format!
(
"Could not retrieve configuration: {}"
,
err
.to_string
()
))
})
?
;
serde_json
::
to_string
(
&
conf
)
.map_err
(|
err
|
{
Error
::
from
(
format!
(
"Could not serialize configuration to json: {}"
,
err
.to_string
()
))
})
let
conf
=
configuration
::
get_configuration
()
.map_err
(
Error
::
from
)
.map_err
(|
err
|
err
.prepend
(
"Could not retrieve configuration"
))
?
;
serde_json
::
to_string
(
&
conf
)
.map_err
(
Error
::
from
)
.map_err
(|
err
|
err
.prepend
(
"Could not serialize configuration to json"
))
}
pub
fn
slice
(
json
:
&
str
)
->
Result
<
String
>
{
let
conf
=
configuration
::
get_configuration
()
.map_err
(|
err
|
{
Error
::
from
(
format!
(
"Could not retrieve configuration: {}"
,
err
.to_string
()
))
})
?
;
let
conf
=
configuration
::
get_configuration
()
.map_err
(
Error
::
from
)
.map_err
(|
err
|
err
.prepend
(
"Could not retrieve configuration"
))
?
;
let
list
:
Vec
<
SliceInfoRequest
>
=
serde_json
::
from_str
(
json
)
.map_err
(|
err
|
Error
::
from
(
format!
(
"Could not deserialize json: {}"
,
err
.to_string
())))
?
;
.map_err
(
Error
::
from
)
.map_err
(|
err
|
err
.prepend
(
"Could not deserialize json"
))
?
;
// let controllers = &configuration.controllers;
let
result
=
list
.into_iter
()
.map
(|
info
|
SliceInfoAnswer
::
from_request
(
info
,
&
conf
.controllers
))
.collect
::
<
Result
<
Vec
<
_
>>>
()
.map_err
(|
err
|
{
Error
::
from
(
format!
(
"Could not get requested slice information: {}"
,
err
.to_string
()
))
})
?
;
serde_json
::
to_string
(
&
result
)
.map_err
(|
err
|
{
Error
::
from
(
format!
(
"Could not serialize slice information to json: {}"
,
err
.to_string
()
))
})
.map_err
(
Error
::
from
)
.map_err
(|
err
|
err
.prepend
(
"Could not get requested slice information"
))
?
;
serde_json
::
to_string
(
&
result
)
.map_err
(
Error
::
from
)
.map_err
(|
err
|
err
.prepend
(
"Could not serialize slice information to json"
))
}
src/show/slice.rs
View file @
2ea286a9
...
...
@@ -24,21 +24,20 @@ impl SliceInfoAnswer {
.keys
.iter
()
.map
(|
key
|
{
let
path
=
controllers
.find_path
(
&
request
.name
,
&
key
)
.map_err
(|
err
|
{
Error
::
from
(
format!
(
"Could not retrieve path to key {} for slice {}: {}"
,
request
.name
,
key
,
err
.to_string
()
))
})
?
;
let
value
=
fs
::
read_to_string
(
&
path
)
.map_err
(|
err
|
{
Error
::
from
(
format!
(
"Could not read from file {}: {}"
,
path
.display
(),
err
.to_string
()
))
})
?
;
let
path
=
controllers
.find_path
(
&
request
.name
,
&
key
)
.map_err
(
Error
::
from
)
.map_err
(|
err
|
{
err
.prepend
(
format!
(
"Could not retrieve path to key {} for slice {}"
,
request
.name
,
key
))
})
?
;
let
value
=
fs
::
read_to_string
(
&
path
)
.map_err
(
Error
::
from
)
.map_err
(|
err
|
{
err
.prepend
(
format!
(
"Could not read from file {}"
,
path
.display
()))
})
?
;
Ok
((
key
.clone
(),
value
))
})
.collect
::
<
Result
<
HashMap
<
_
,
_
>>>
()
?
;
Ok
(
SliceInfoAnswer
{
...
...
src/transaction/fs/find_get_set_value.rs
View file @
2ea286a9
...
...
@@ -124,11 +124,11 @@ impl Command for FindGetSetValue {
trace!
(
"{{rollback}} Writing to file {}"
,
path
.display
());
fs
::
write
(
path
,
old_value
)
.map
(|
_
|
CommandResult
::
from
(()))
.map_err
(
Error
::
from
)
.map_err
(|
err
|
{
Error
::
from
(
format!
(
"{{rollback}} Could not write to file {}: {}"
,
path
.display
(),
err
.to_string
()
err
.prepend
(
format!
(
"{{rollback}} Could not write to file {}"
,
path
.display
()
))
})
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment