vm-manager: More error handling

This commit is contained in:
Qubasa
2024-01-02 06:23:55 +01:00
parent 1fc524e53e
commit 01977b2e2a
3 changed files with 25 additions and 20 deletions

View File

@@ -10,7 +10,7 @@ from clan_cli.flakes.inspect import FlakeConfig, inspect_flake
from ..clan_uri import ClanURI
from ..dirs import user_history_file
from ..locked_open import read_history_file, write_history_file
from ..errors import ClanError
class EnhancedJSONEncoder(json.JSONEncoder):
def default(self, o: Any) -> Any:
@@ -56,8 +56,7 @@ def list_history() -> list[HistoryEntry]:
parsed[i] = merge_dicts(p, p["settings"])
logs = [HistoryEntry(**p) for p in parsed]
except (json.JSONDecodeError, TypeError) as ex:
print("Failed to load history. Invalid JSON.")
print(f"{user_history_file()}: {ex}")
raise ClanError(f"History file at {user_history_file()} is corrupted") from ex
return logs

View File

@@ -4,7 +4,9 @@ from pathlib import Path
from typing import Any
import gi
from clan_cli import history
from clan_cli.history.list import list_history
from .errors.show_error import show_error_dialog
gi.require_version("GdkPixbuf", "2.0")
@@ -64,8 +66,9 @@ def get_initial_vms(
) -> list[VM]:
vm_list = []
try:
# Execute `clan flakes add <path>` to democlan for this to work
for entry in history.list.list_history():
for entry in list_history():
icon = assets.loc / "placeholder.jpeg"
if entry.flake.icon is not None:
icon = entry.flake.icon
@@ -82,6 +85,8 @@ def get_initial_vms(
_flake_attr=entry.flake.flake_attr,
)
vm_list.append(VM(base=base))
except Exception as e:
show_error_dialog(e)
# start/end slices can be used for pagination
return vm_list[start:end]

View File

@@ -33,6 +33,7 @@ class OverviewWindow(Gtk.ApplicationWindow):
set_selected=self.set_selected,
selected_vm=None,
)
# Add named stacks
self.stack.add_titled(clan_list, "list", "List")
self.stack.add_titled(