Show better error when standard library cannot be found.

This commit is contained in:
Dominik Picheta 2018-01-09 21:56:12 +00:00
commit 182893c529
2 changed files with 21 additions and 3 deletions

View file

@ -188,7 +188,10 @@ proc setupVM(module: PSym; scriptName: string, flags: Flags): PEvalContext =
else:
flags[key] = @[value]
proc getNimPrefixDir(): string =
proc isValidLibPath(lib: string): bool =
return fileExists(lib / "system.nim")
proc getNimPrefixDir: string =
let env = getEnv("NIM_LIB_PREFIX")
if env != "":
return env
@ -221,6 +224,19 @@ proc execScript(scriptName: string, flags: Flags, options: Options): PSym =
# Ensure the compiler can find its standard library #220.
compiler_options.gPrefixDir = getNimPrefixDir()
# Verify that lib path points to existing stdlib.
compiler_options.setDefaultLibpath()
if not isValidLibPath(compiler_options.libpath):
let msg = "Nimble cannot find Nim's standard library.\nLast try in:\n - $1" %
compiler_options.libpath
let hint = "Nimble does its best to find Nim's standard library, " &
"sometimes this fails. You can set the environment variable " &
"NIM_LIB_PREFIX to where Nim's `lib` directory is located as " &
"a workaround. " &
"See https://github.com/nim-lang/nimble#troubleshooting for " &
"more info."
raiseNimbleError(msg, hint)
let pkgName = scriptName.splitFile.name
# Ensure that "nimblepkg/nimscriptapi" is in the PATH.

View file

@ -329,12 +329,14 @@ proc readPackageInfo(nf: NimbleFile, options: Options,
try:
readPackageInfoFromNims(nf, options, result)
result.isNimScript = true
except NimbleError:
except NimbleError as exc:
if exc.hint.len > 0:
raise
let msg = "Could not read package info file in " & nf & ";\n" &
" Reading as ini file failed with: \n" &
" " & iniError.msg & ".\n" &
" Evaluating as NimScript file failed with: \n" &
" " & getCurrentExceptionMsg() & "."
" " & exc.msg & "."
raise newException(NimbleError, msg)
# By default specialVersion is the same as version.