From ede74c6a2a03c2f9d54dfab1f2df4d9f753b8916 Mon Sep 17 00:00:00 2001 From: Tim Miller Date: Mon, 29 Jun 2026 13:11:34 -0400 Subject: [PATCH] Throw a clear error when stack.yaml(.lock) path is missing Guard the `stackYaml` and `stackYamlLock` paths with `builtins.pathExists` so that a missing file produces an actionable message naming the likely cause, instead of a bare `error: path '...' does not exist` from deep inside the YAML-reading IFD. When the paths exist they are returned unchanged, so there is no behavior change for normal builds. Co-Authored-By: Claude Opus 4.8 (1M context) --- nix/build-support/stacklock2nix/default.nix | 23 ++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/nix/build-support/stacklock2nix/default.nix b/nix/build-support/stacklock2nix/default.nix index 2431348..33bf49e 100644 --- a/nix/build-support/stacklock2nix/default.nix +++ b/nix/build-support/stacklock2nix/default.nix @@ -257,18 +257,31 @@ assert stackYaml != null || stackYamlLock != null; let + # Throw a clear error if the path is missing, instead of a bare + # `path '...' does not exist` from deep inside the YAML-reading IFD. + # assertPathExists :: String -> Path -> Path + assertPathExists = fileDesc: path: + if builtins.pathExists path then + path + else + throw + ("stacklock2nix: ${fileDesc} not found at ${toString path}. This usually " + + "means stacklock2nix is being evaluated without the full repository present " + + "(for example, a Docker build that copies only a subset of the source tree)."); + stackYamlReal = if stackYaml == null then builtins.throw "ERROR: logic for inferring the stack.yaml path from stack.yaml.lock path has not yet been implemented. Please send a PR!" else - stackYaml; + assertPathExists "stack.yaml" stackYaml; stackYamlLockReal = - if stackYamlLock == null then - stackYaml + ".lock" - else - stackYamlLock; + assertPathExists "stack.yaml.lock" + (if stackYamlLock == null then + stackYaml + ".lock" + else + stackYamlLock); readYAML = callPackage ./read-yaml.nix {};