Skip to content

Commit c4e5c9c

Browse files
committed
handle some remaining cases in output conversion, including u64
1 parent 9d8aff2 commit c4e5c9c

2 files changed

Lines changed: 13 additions & 13 deletions

File tree

src/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,6 @@ impl DbusClient {
7979
let resp = self.conn.send_with_reply_and_block(message, self.config.timeout.item)
8080
.map_err(|err| error!(err.to_string()))?;
8181

82-
Ok(crate::convert::from_message(&resp)?)
82+
crate::convert::from_message(&resp).map_err(|err| error!(err))
8383
}
8484
}

src/convert.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
use dbus::{Message, arg::{ArgType, RefArg}};
2-
use nu_plugin::LabeledError;
32
use nu_protocol::{Value, Span, Record};
43

5-
pub fn from_message(message: &Message) -> Result<Value, LabeledError> {
4+
pub fn from_message(message: &Message) -> Result<Value, String> {
65
let mut out = vec![];
76
for refarg in message.iter_init() {
8-
if let Some(o) = from_refarg(&refarg) {
9-
out.push(o);
10-
}
7+
out.push(from_refarg(&refarg)?);
118
}
129
Ok(Value::list(out, Span::unknown()))
1310
}
1411

15-
pub fn from_refarg(refarg: &dyn RefArg) -> Option<Value> {
16-
Some(match refarg.arg_type() {
12+
pub fn from_refarg(refarg: &dyn RefArg) -> Result<Value, String> {
13+
Ok(match refarg.arg_type() {
1714
ArgType::Array => {
1815
if refarg.signature().starts_with("a{") {
1916
// This is a dictionary
@@ -52,6 +49,10 @@ pub fn from_refarg(refarg: &dyn RefArg) -> Option<Value> {
5249
ArgType::Byte | ArgType::Int16 | ArgType::UInt16 | ArgType::Int32 |
5350
ArgType::UInt32 | ArgType::Int64 | ArgType::UnixFd =>
5451
Value::int(refarg.as_i64().unwrap(), Span::unknown()),
52+
53+
// Nushell doesn't support u64, so present it as a string
54+
ArgType::UInt64 => Value::string(refarg.as_u64().unwrap().to_string(), Span::unknown()),
55+
5556
// Floats
5657
ArgType::Double =>
5758
Value::float(refarg.as_f64().unwrap(), Span::unknown()),
@@ -61,10 +62,9 @@ pub fn from_refarg(refarg: &dyn RefArg) -> Option<Value> {
6162
refarg.as_iter().unwrap().map(from_refarg).flatten().collect(),
6263
Span::unknown()),
6364

64-
ArgType::DictEntry => todo!(),
65-
ArgType::UInt64 => todo!(), // nushell only supports up to i64
66-
67-
// End of iterator
68-
ArgType::Invalid => return None,
65+
ArgType::DictEntry =>
66+
return Err("Encountered dictionary entry outside of dictionary".into()),
67+
ArgType::Invalid =>
68+
return Err("Encountered invalid D-Bus value".into()),
6969
})
7070
}

0 commit comments

Comments
 (0)