summary refs log tree commit diff
path: root/LibSystemdCli
diff options
context:
space:
mode:
Diffstat (limited to 'LibSystemdCli')
-rw-r--r--LibSystemdCli/CommandExecutor.cs10
-rw-r--r--LibSystemdCli/SystemdExecutor.cs14
2 files changed, 22 insertions, 2 deletions
diff --git a/LibSystemdCli/CommandExecutor.cs b/LibSystemdCli/CommandExecutor.cs

index 096f1c1..8a21bc5 100644 --- a/LibSystemdCli/CommandExecutor.cs +++ b/LibSystemdCli/CommandExecutor.cs
@@ -27,6 +27,16 @@ public class CommandExecutor throw new Exception($"Command {command} {args} failed with exit code {process.ExitCode} and error: {error}"); } + if (string.IsNullOrWhiteSpace(output)) + { + Console.WriteLine($"[{DateTime.Now:O}] Command {command} {args} produced no output."); + } + + if (!string.IsNullOrWhiteSpace(error)) + { + Console.WriteLine($"[{DateTime.Now:O}] Command {command} {args} produced error output: {error}"); + } + return output; } diff --git a/LibSystemdCli/SystemdExecutor.cs b/LibSystemdCli/SystemdExecutor.cs
index ead11fd..f252891 100644 --- a/LibSystemdCli/SystemdExecutor.cs +++ b/LibSystemdCli/SystemdExecutor.cs
@@ -8,7 +8,15 @@ public class SystemdExecutor { public static async IAsyncEnumerable<SystemdUnitListItem> GetUnits() { var output = await CommandExecutor.ExecuteCommand("systemctl", "list-units --all --no-legend --no-pager --no-legend -o json-pretty"); - var data = JsonSerializer.Deserialize<List<SystemdUnitListItem>>(output); + List<SystemdUnitListItem>? data; + try { + data = JsonSerializer.Deserialize<List<SystemdUnitListItem>>(output); + } + catch (Exception ex) { + Console.WriteLine("Failed to parse systemctl output: " + ex); + Console.WriteLine("Output was: " + output); + yield break; + } foreach (var unit in data) { try { @@ -16,7 +24,9 @@ public class SystemdExecutor { // Console.WriteLine(fragmentOutput); unit.FragmentPaths = fragmentOutput.Split('\n', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries).ToList(); } - catch { } + catch (Exception e) { + Console.WriteLine("Failed to get fragment path for unit " + unit.Unit + ": " + e); + } yield return unit; // await Task.Delay(100);