11use dbus:: { Message , arg:: { ArgType , RefArg } } ;
2- use nu_plugin:: LabeledError ;
32use 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