1 files changed, 12 insertions, 2 deletions
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);
|