@@ -3,8 +3,7 @@ use dbus::{
33 channel:: { BusType , Channel } ,
44 Message ,
55} ;
6- use nu_plugin:: LabeledError ;
7- use nu_protocol:: { Spanned , Value } ;
6+ use nu_protocol:: { LabeledError , Spanned , Value } ;
87
98use crate :: {
109 config:: { DbusBusChoice , DbusClientConfig } ,
@@ -23,11 +22,8 @@ pub struct DbusClient {
2322// Convenience macros for error handling
2423macro_rules! validate_with {
2524 ( $type: ty, $spanned: expr) => {
26- <$type>:: new( & $spanned. item) . map_err( |msg| LabeledError {
27- label: msg,
28- msg: "this argument is incorrect" . into( ) ,
29- span: Some ( $spanned. span) ,
30- } )
25+ <$type>:: new( & $spanned. item)
26+ . map_err( |msg| LabeledError :: new( "Invalid argument" ) . with_label( msg, $spanned. span) )
3127 } ;
3228}
3329
@@ -44,10 +40,11 @@ impl DbusClient {
4440 Ok ( ch)
4541 } ) ,
4642 }
47- . map_err ( |err| LabeledError {
48- label : err. to_string ( ) ,
49- msg : "while connecting to D-Bus as specified here" . into ( ) ,
50- span : Some ( config. bus_choice . span ) ,
43+ . map_err ( |err| {
44+ LabeledError :: new ( err. to_string ( ) ) . with_label (
45+ "while connecting to D-Bus as specified here" ,
46+ config. bus_choice . span ,
47+ )
5148 } ) ?;
5249 Ok ( DbusClient {
5350 config,
@@ -56,11 +53,7 @@ impl DbusClient {
5653 }
5754
5855 fn error ( & self , err : impl std:: fmt:: Display , msg : impl std:: fmt:: Display ) -> LabeledError {
59- LabeledError {
60- label : err. to_string ( ) ,
61- msg : msg. to_string ( ) ,
62- span : Some ( self . config . span ) ,
63- }
56+ LabeledError :: new ( err. to_string ( ) ) . with_label ( msg. to_string ( ) , self . config . span )
6457 }
6558
6659 /// Introspect a D-Bus object
@@ -107,20 +100,22 @@ impl DbusClient {
107100 let node = self . introspect ( dest, object) ?;
108101
109102 if let Some ( sig) = node. get_method_args_signature ( & interface. item , & method. item ) {
110- DbusType :: parse_all ( & sig) . map_err ( |err| LabeledError {
111- label : format ! (
103+ DbusType :: parse_all ( & sig) . map_err ( |err| {
104+ LabeledError :: new ( format ! (
112105 "while getting interface {:?} method {:?} signature: {}" ,
113106 interface. item, method. item, err
114- ) ,
115- msg : "try running with --no-introspect or --signature" . into ( ) ,
116- span : Some ( self . config . span ) ,
107+ ) )
108+ . with_label (
109+ "try running with --no-introspect or --signature" ,
110+ self . config . span ,
111+ )
117112 } )
118113 } else {
119- Err ( LabeledError {
120- label : format ! ( "Method {:?} not found on {:?}" , method . item , interface . item ) ,
121- msg : "check that this method/interface is correct" . into ( ) ,
122- span : Some ( method . span ) ,
123- } )
114+ Err ( LabeledError :: new ( format ! (
115+ "Method {:?} not found on {:?}" ,
116+ method. item , interface . item
117+ ) )
118+ . with_label ( "check that this method/interface is correct" , method . span ) )
124119 }
125120 }
126121
@@ -135,23 +130,25 @@ impl DbusClient {
135130 let node = self . introspect ( dest, object) ?;
136131
137132 if let Some ( sig) = node. get_property_signature ( & interface. item , & property. item ) {
138- DbusType :: parse_all ( sig) . map_err ( |err| LabeledError {
139- label : format ! (
133+ DbusType :: parse_all ( sig) . map_err ( |err| {
134+ LabeledError :: new ( format ! (
140135 "while getting interface {:?} property {:?} signature: {}" ,
141136 interface. item, property. item, err
142- ) ,
143- msg : "try running with --no-introspect or --signature" . into ( ) ,
144- span : Some ( self . config . span ) ,
137+ ) )
138+ . with_label (
139+ "try running with --no-introspect or --signature" ,
140+ self . config . span ,
141+ )
145142 } )
146143 } else {
147- Err ( LabeledError {
148- label : format ! (
149- "Property {:?} not found on {:?}" ,
150- property . item , interface . item
151- ) ,
152- msg : "check that this property/ interface is correct" . into ( ) ,
153- span : Some ( property. span ) ,
154- } )
144+ Err ( LabeledError :: new ( format ! (
145+ "Property {:?} not found on {:?}" ,
146+ property . item , interface . item
147+ ) )
148+ . with_label (
149+ "check that this property or interface is correct" ,
150+ property. span ,
151+ ) )
155152 }
156153 }
157154
@@ -176,10 +173,8 @@ impl DbusClient {
176173 // Parse the signature
177174 let mut valid_signature = signature
178175 . map ( |s| {
179- DbusType :: parse_all ( & s. item ) . map_err ( |err| LabeledError {
180- label : err,
181- msg : "in signature specified here" . into ( ) ,
182- span : Some ( s. span ) ,
176+ DbusType :: parse_all ( & s. item ) . map_err ( |err| {
177+ LabeledError :: new ( err) . with_label ( "in signature specified here" , s. span )
183178 } )
184179 } )
185180 . transpose ( ) ?;
@@ -195,7 +190,7 @@ impl DbusClient {
195190 "Warning: D-Bus introspection failed on {:?}. \
196191 Use `--no-introspect` or pass `--signature` to silence this warning. \
197192 Cause: {}",
198- object. item, err. label
193+ object. item, err
199194 ) ;
200195 }
201196 }
@@ -314,10 +309,8 @@ impl DbusClient {
314309 // Parse the signature
315310 let mut valid_signature = signature
316311 . map ( |s| {
317- DbusType :: parse_all ( & s. item ) . map_err ( |err| LabeledError {
318- label : err,
319- msg : "in signature specified here" . into ( ) ,
320- span : Some ( s. span ) ,
312+ DbusType :: parse_all ( & s. item ) . map_err ( |err| {
313+ LabeledError :: new ( err) . with_label ( "in signature specified here" , s. span )
321314 } )
322315 } )
323316 . transpose ( ) ?;
@@ -333,7 +326,7 @@ impl DbusClient {
333326 "Warning: D-Bus introspection failed on {:?}. \
334327 Use `--no-introspect` or pass `--signature` to silence this warning. \
335328 Cause: {}",
336- object. item, err. label
329+ object. item, err
337330 ) ;
338331 }
339332 }
0 commit comments