mirror of
https://github.com/nix-community/disko.git
synced 2026-12-01 21:43:29 +01:00
disko2: Move to error codes and dedicated error rendering
This splits the concern of how to display errors off from the business logic. This should make it easier to test functionality and allow us to concentrate on how to actually display and communicate errors to the user. At some point this might also make i18n feasible, because you only have to swap out a single file. This hasn't quite fixed the debug/trace story yet. It should be possible to simply insert a "debug" command into any pipeline and see the context and state at that point.
This commit is contained in:
1 parent
684adb7e64
commit
f2618b5490
4 files changed
+169
-42
No files matched your search
+5
-11
@@ -1,5 +1,7 @@
|
||||
use libexec-dir.nu
|
||||
|
||||
use std log
|
||||
|
||||
alias nix = ^nix --extra-experimental-features nix-command --extra-experimental-features flakes
|
||||
alias nix-eval-expr = nix eval --impure --json --expr
|
||||
|
||||
@@ -11,10 +13,7 @@ def eval-config [args: record]: nothing -> record {
|
||||
| if $in.exit_code != 0 {
|
||||
{
|
||||
success: false
|
||||
messages: [
|
||||
$"Failed to evaluate disko config with args ($args)!"
|
||||
$"Error from nix eval: ($in.stderr)"
|
||||
]
|
||||
messages: [ { code: ERR_EVAL_CONFIG_FAILED, details: { args: $args, stderr: $in.stderr } } ]
|
||||
}
|
||||
} else {
|
||||
$in.stdout
|
||||
@@ -32,9 +31,7 @@ export def eval-disko-file []: path -> record {
|
||||
if not ($config | path exists) {
|
||||
return {
|
||||
success: false
|
||||
messages: [
|
||||
$"File (ansi blue)($config)(ansi reset) does not exist."
|
||||
]
|
||||
messages: [ { code: ERR_FILE_NOT_FOUND, details: { path: $config } } ]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,10 +53,7 @@ export def eval-flake []: string -> record {
|
||||
} else {
|
||||
return {
|
||||
success: false
|
||||
messages: [
|
||||
$"Flake-uri ($flakeUri) does not contain an attribute."
|
||||
"Please append an attribute like \"#foo\" to the flake-uri."
|
||||
]
|
||||
messages: [ { code: ERR_FLAKE_URI_NO_ATTRIBUTE, details: { flakeUri: $flakeUri } } ]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user