Skip to content

Commit

Permalink
feat: lake: detailed Reservoir fetch error (#6231)
Browse files Browse the repository at this point in the history
This PR improves the errors Lake produces when it fails to fetch a
dependency from Reservoir. If the package is not indexed, it will
produce a suggestion about how to require it from GitHub.

Closes #5330.
  • Loading branch information
tydeu authored and kim-em committed Nov 29, 2024
1 parent 062b9a7 commit 410fab7
Show file tree
Hide file tree
Showing 7 changed files with 307 additions and 128 deletions.
2 changes: 1 addition & 1 deletion src/lake/Lake/Build/Actions.lean
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def compileLeanModule
unless txt.isEmpty do
logInfo s!"stdout:\n{txt}"
unless out.stderr.isEmpty do
logInfo s!"stderr:\n{out.stderr}"
logInfo s!"stderr:\n{out.stderr.trim}"
if out.exitCode ≠ 0 then
error s!"Lean exited with code {out.exitCode}"

Expand Down
30 changes: 27 additions & 3 deletions src/lake/Lake/Load/Materialize.lean
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,25 @@ structure MaterializedDep where
@[inline] def MaterializedDep.configFile (self : MaterializedDep) :=
self.manifestEntry.configFile

def pkgNotIndexed (scope name : String) (rev? : Option String := none) : String :=
let (leanRev, tomlRev) :=
if let some rev := rev? then
(s!" @ {repr rev}", s! "\n rev = {repr rev}")
else ("", "")
s!"{scope}/{name}: package not found on Reservoir.
If the package is on GitHub, you can add a Git source. For example:
require ...
from git \"https://github.com/{scope}/{name}\"{leanRev}
or, if using TOML:
[[require]]
git = \"https://github.com/{scope}/{name}\"{tomlRev}
...
"

/--
Materializes a configuration dependency.
For Git dependencies, updates it to the latest input revision.
Expand Down Expand Up @@ -131,9 +150,14 @@ def Dependency.materialize
else
error s!"{dep.name}: unsupported dependency version format '{ver}' (should be \"git#>rev>\")"
let depName := dep.name.toString (escape := false)
let some pkg ← Reservoir.fetchPkg? lakeEnv dep.scope depName
| error s!"{dep.scope}/{depName}: could not materialize package: \
dependency has no explicit source and was not found on Reservoir"
let pkg ←
match (← Reservoir.fetchPkg? lakeEnv dep.scope depName |>.toLogT) with
| .ok (some pkg) => pure pkg
| .ok none => error <| pkgNotIndexed dep.scope depName verRev?
| .error e =>
logError s!"{dep.scope}/{depName}: could not materialize package: \
this may be a transient error or a bug in Lake or Reservoir"
throw e
let relPkgDir := relPkgsDir / pkg.name
match pkg.gitSrc? with
| some (.git _ url githubUrl? defaultBranch? subDir?) =>
Expand Down
Loading

0 comments on commit 410fab7

Please sign in to comment.