1
1
use crossterm:: event:: { KeyCode , KeyEvent , KeyModifiers } ;
2
- use duct:: cmd;
3
2
use futures:: Future ;
4
3
use indexmap:: IndexMap ;
5
4
use itertools:: Itertools ;
@@ -18,7 +17,10 @@ use tokio_util::sync::CancellationToken;
18
17
use tracing:: { error, info, warn} ;
19
18
use tui_input:: { backend:: crossterm:: EventHandler , Input } ;
20
19
21
- use std:: { process:: Stdio , time:: Duration } ;
20
+ use std:: {
21
+ process:: { Command , Stdio } ,
22
+ time:: Duration ,
23
+ } ;
22
24
23
25
use super :: { logger:: Logger , Component , Frame } ;
24
26
use crate :: {
@@ -365,7 +367,11 @@ impl Component for Home {
365
367
let _ = tx. send ( Action :: SetUnitFilePath { unit : unit. clone ( ) , path } ) ;
366
368
let _ = tx. send ( Action :: Render ) ;
367
369
} ,
368
- Err ( e) => error ! ( "Error getting unit file path for {}: {}" , unit. name, e) ,
370
+ Err ( e) => {
371
+ let _ = tx. send ( Action :: SetUnitFilePath { unit : unit. clone ( ) , path : "(could not be determined)" . into ( ) } ) ;
372
+ let _ = tx. send ( Action :: Render ) ;
373
+ error ! ( "Error getting unit file path for {}: {}" , unit. name, e) ;
374
+ } ,
369
375
}
370
376
371
377
// First, get the N lines in a batch
@@ -380,17 +386,24 @@ impl Component for Home {
380
386
args. push ( "--user" ) ;
381
387
}
382
388
383
- match cmd ( "journalctl" , args) . read ( ) {
384
- Ok ( stdout) => {
385
- info ! ( "Got logs for {} in {:?}" , unit. name, start. elapsed( ) ) ;
386
-
387
- let mut logs = stdout. split ( '\n' ) . map ( String :: from) . collect_vec ( ) ;
388
-
389
- if logs. is_empty ( ) || logs[ 0 ] . is_empty ( ) {
390
- logs. push ( String :: from ( "No logs found/available. Maybe try relaunching with `sudo systemctl-tui`" ) ) ;
389
+ match Command :: new ( "journalctl" ) . args ( & args) . output ( ) {
390
+ Ok ( output) => {
391
+ if output. status . success ( ) {
392
+ info ! ( "Got logs for {} in {:?}" , unit. name, start. elapsed( ) ) ;
393
+ if let Ok ( stdout) = std:: str:: from_utf8 ( & output. stdout ) {
394
+ let mut logs = stdout. trim ( ) . split ( '\n' ) . map ( String :: from) . collect_vec ( ) ;
395
+
396
+ if logs. is_empty ( ) || logs[ 0 ] . is_empty ( ) {
397
+ logs. push ( String :: from ( "No logs found/available. Maybe try relaunching with `sudo systemctl-tui`" ) ) ;
398
+ }
399
+ let _ = tx. send ( Action :: SetLogs { unit : unit. clone ( ) , logs } ) ;
400
+ let _ = tx. send ( Action :: Render ) ;
401
+ } else {
402
+ warn ! ( "Error parsing stdout for {}" , unit. name) ;
403
+ }
404
+ } else {
405
+ warn ! ( "Error getting logs for {}: {}" , unit. name, String :: from_utf8_lossy( & output. stderr) ) ;
391
406
}
392
- let _ = tx. send ( Action :: SetLogs { unit : unit. clone ( ) , logs } ) ;
393
- let _ = tx. send ( Action :: Render ) ;
394
407
} ,
395
408
Err ( e) => warn ! ( "Error getting logs for {}: {}" , unit. name, e) ,
396
409
}
0 commit comments