@@ -90,37 +90,65 @@ impl CommandExecute for NixInstallerCli {
9090 where
9191 T : crate :: feedback:: Feedback ,
9292 {
93- match self . subcommand {
94- NixInstallerSubcommand :: Plan ( plan) => plan. execute ( feedback) . await ,
95- NixInstallerSubcommand :: SelfTest ( self_test) => self_test. execute ( feedback) . await ,
96- NixInstallerSubcommand :: Install ( install) => {
97- let ret = install. execute ( feedback. clone ( ) ) . await ;
98-
99- if matches ! (
100- target_lexicon:: OperatingSystem :: host( ) ,
101- target_lexicon:: OperatingSystem :: MacOSX { .. }
102- | target_lexicon:: OperatingSystem :: Darwin
103- ) {
104- #[ allow( clippy:: collapsible_if) ]
105- if ret. is_err ( ) || ret. as_ref ( ) . is_ok_and ( |code| code == & ExitCode :: FAILURE ) {
106- let msg = feedback
107- . get_feature_ptr_payload :: < String > ( "dni-det-msg-fail-pkg-ptr" )
108- . await
109- . unwrap_or ( FAIL_PKG_SUGGEST . into ( ) ) ;
110- tracing:: warn!( "{}\n " , msg. trim( ) ) ;
111-
112- return Ok ( ExitCode :: FAILURE ) ;
113- }
114- }
93+ let feedback_clone = feedback. clone ( ) ;
11594
116- ret
117- } ,
118- NixInstallerSubcommand :: Repair ( repair) => repair. execute ( feedback) . await ,
119- NixInstallerSubcommand :: Uninstall ( revert) => revert. execute ( feedback) . await ,
95+ let is_install_subcommand = matches ! ( self . subcommand, NixInstallerSubcommand :: Install ( _) ) ;
96+
97+ let ret = match self . subcommand {
98+ NixInstallerSubcommand :: Plan ( plan) => plan. execute ( feedback_clone) . await ,
99+ NixInstallerSubcommand :: SelfTest ( self_test) => self_test. execute ( feedback_clone) . await ,
100+ NixInstallerSubcommand :: Install ( install) => install. execute ( feedback_clone) . await ,
101+ NixInstallerSubcommand :: Repair ( repair) => repair. execute ( feedback_clone) . await ,
102+ NixInstallerSubcommand :: Uninstall ( revert) => revert. execute ( feedback_clone) . await ,
120103 NixInstallerSubcommand :: SplitReceipt ( split_receipt) => {
121- split_receipt. execute ( feedback ) . await
104+ split_receipt. execute ( feedback_clone ) . await
122105 } ,
106+ } ;
107+
108+ let maybe_cancelled = ret. as_ref ( ) . err ( ) . and_then ( |err| {
109+ err. root_cause ( )
110+ . downcast_ref :: < crate :: NixInstallerError > ( )
111+ . and_then ( |err| {
112+ if matches ! ( err, crate :: NixInstallerError :: Cancelled ) {
113+ return Some ( err) ;
114+ }
115+ None
116+ } )
117+ } ) ;
118+
119+ if let Some ( cancelled) = maybe_cancelled {
120+ eprintln ! ( "{}" , cancelled. red( ) ) ;
121+ return Ok ( ExitCode :: FAILURE ) ;
122+ }
123+
124+ let is_macos = matches ! (
125+ target_lexicon:: OperatingSystem :: host( ) ,
126+ target_lexicon:: OperatingSystem :: MacOSX { .. }
127+ | target_lexicon:: OperatingSystem :: Darwin
128+ ) ;
129+
130+ if is_install_subcommand && is_macos {
131+ let is_ok_but_failed = ret. as_ref ( ) . is_ok_and ( |code| code == & ExitCode :: FAILURE ) ;
132+ let is_error = ret. as_ref ( ) . is_err ( ) ;
133+
134+ if is_error || is_ok_but_failed {
135+ let msg = feedback
136+ . get_feature_ptr_payload :: < String > ( "dni-det-msg-fail-pkg-ptr" )
137+ . await
138+ . unwrap_or ( FAIL_PKG_SUGGEST . into ( ) ) ;
139+
140+ // NOTE: If the error bubbled up, print it before we log the pkg suggestion
141+ if let Err ( ref err) = ret {
142+ eprintln ! ( "{err:?}\n " ) ;
143+ }
144+
145+ tracing:: warn!( "{}\n " , msg. trim( ) ) ;
146+
147+ return Ok ( ExitCode :: FAILURE ) ;
148+ }
123149 }
150+
151+ ret
124152 }
125153}
126154
0 commit comments