about summary refs log tree commit diff
path: root/tvix
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2023-01-16T10·27+0300
committertazjin <tazjin@tvl.su>2023-01-20T15·39+0000
commit259faea2b229edd8f2e31d0903b5fd185036b4a4 (patch)
tree7048af93655472774ab93953cf7682cd07d19425 /tvix
parent7d0456fa0e6330d24f0234a51f8bec85f26686d3 (diff)
feat(tvix/cli): add `errors` module with drv construction errors r/5709
These will be threaded through to eval through the new `TvixError`
variant.

Change-Id: Ia0d3f8710dcf26bb95015cd2a6a2b2911f06343f
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7842
Reviewed-by: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix')
-rw-r--r--tvix/Cargo.lock1
-rw-r--r--tvix/Cargo.nix4
-rw-r--r--tvix/cli/Cargo.toml1
-rw-r--r--tvix/cli/src/errors.rs49
-rw-r--r--tvix/cli/src/main.rs1
5 files changed, 56 insertions, 0 deletions
diff --git a/tvix/Cargo.lock b/tvix/Cargo.lock
index acf516900fd6..83905549c92d 100644
--- a/tvix/Cargo.lock
+++ b/tvix/Cargo.lock
@@ -2310,6 +2310,7 @@ dependencies = [
  "dirs",
  "rustyline",
  "smol_str",
+ "tvix-derivation",
  "tvix-eval",
 ]
 
diff --git a/tvix/Cargo.nix b/tvix/Cargo.nix
index cb86a7fe5ba7..cb8ad6e56e49 100644
--- a/tvix/Cargo.nix
+++ b/tvix/Cargo.nix
@@ -6858,6 +6858,10 @@ rec {
             packageId = "smol_str";
           }
           {
+            name = "tvix-derivation";
+            packageId = "tvix-derivation";
+          }
+          {
             name = "tvix-eval";
             packageId = "tvix-eval";
           }
diff --git a/tvix/cli/Cargo.toml b/tvix/cli/Cargo.toml
index f3324f2611ea..45ed05e089d3 100644
--- a/tvix/cli/Cargo.toml
+++ b/tvix/cli/Cargo.toml
@@ -9,6 +9,7 @@ path = "src/main.rs"
 
 [dependencies]
 tvix-eval = { path = "../eval" }
+tvix-derivation = { path = "../derivation" }
 rustyline = "10.0.0"
 clap = { version = "4.0", features = ["derive", "env"] }
 dirs = "4.0.0"
diff --git a/tvix/cli/src/errors.rs b/tvix/cli/src/errors.rs
new file mode 100644
index 000000000000..8eaaef1579aa
--- /dev/null
+++ b/tvix/cli/src/errors.rs
@@ -0,0 +1,49 @@
+use std::{error, fmt::Display, rc::Rc};
+use tvix_derivation::DerivationError;
+
+#[derive(Debug)]
+pub enum Error {
+    // Errors related to derivation construction
+    DuplicateOutput(String),
+    ConflictingOutputTypes,
+    DuplicateEnvVar(String),
+    ShadowedOutput(String),
+    InvalidDerivation(DerivationError),
+}
+
+impl Display for Error {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        match self {
+            Error::DuplicateOutput(name) => {
+                write!(f, "an output with the name '{name}' is already defined")
+            }
+
+            Error::ConflictingOutputTypes => write!(
+                f,
+                "fixed-output derivations can only have the default `out`-output"
+            ),
+
+            Error::DuplicateEnvVar(name) => write!(
+                f,
+                "the environment variable '{name}' has already been set in this derivation"
+            ),
+            Error::ShadowedOutput(name) => write!(
+                f,
+                "the environment variable '{name}' shadows the name of an output"
+            ),
+            Error::InvalidDerivation(error) => write!(f, "invalid derivation parameters: {error}"),
+        }
+    }
+}
+
+impl error::Error for Error {
+    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
+        None
+    }
+}
+
+impl From<Error> for tvix_eval::ErrorKind {
+    fn from(err: Error) -> Self {
+        tvix_eval::ErrorKind::TvixError(Rc::new(err))
+    }
+}
diff --git a/tvix/cli/src/main.rs b/tvix/cli/src/main.rs
index 242cece9ecd2..6757044750fe 100644
--- a/tvix/cli/src/main.rs
+++ b/tvix/cli/src/main.rs
@@ -1,3 +1,4 @@
+mod errors;
 mod known_paths;
 mod nix_compat;
 mod refscan;