mirror of
https://github.com/nix-community/disko.git
synced 2026-11-30 21:13:28 +01:00
disko2: Make messages type-safe and modular
Using untyped dicts was not a safe way to pass arguments to error message rendering. Also, having one giant match statement wouldn't scale well. Using function pointers and kwargs, mypy can now properly check whether all required arguments are passed to DiskoMessage(). As a bonus, it's now easy to use the "Go to definition" LSP command for error codes, which wasn't possible before.
This commit is contained in:
1 parent
4db452e40a
commit
a6944c6bea
11 files changed
+242
-201
No files matched your search
@@ -1,5 +1,7 @@
|
||||
import subprocess
|
||||
|
||||
from disko_lib.messages.msgs import err_command_failed
|
||||
|
||||
from .logging import debug
|
||||
from .result import DiskoError, DiskoResult, DiskoSuccess
|
||||
|
||||
@@ -23,11 +25,9 @@ def run(args: list[str]) -> DiskoResult[str]:
|
||||
return DiskoSuccess(result.stdout, "run command")
|
||||
|
||||
return DiskoError.single_message(
|
||||
"ERR_COMMAND_FAILED",
|
||||
{
|
||||
"command": command,
|
||||
"stderr": result.stderr,
|
||||
"exit_code": result.returncode,
|
||||
},
|
||||
err_command_failed,
|
||||
"run command",
|
||||
command=command,
|
||||
stderr=result.stderr,
|
||||
exit_code=result.returncode,
|
||||
)
|
||||
Reference in new issue
Block a user