From 182893c5290dabd2b7cf0ce2b264f39b17009e58 Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Tue, 9 Jan 2018 21:56:12 +0000 Subject: [PATCH] Show better error when standard library cannot be found. --- src/nimblepkg/nimscriptsupport.nim | 18 +++++++++++++++++- src/nimblepkg/packageparser.nim | 6 ++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/nimblepkg/nimscriptsupport.nim b/src/nimblepkg/nimscriptsupport.nim index c186458..50567da 100644 --- a/src/nimblepkg/nimscriptsupport.nim +++ b/src/nimblepkg/nimscriptsupport.nim @@ -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. diff --git a/src/nimblepkg/packageparser.nim b/src/nimblepkg/packageparser.nim index 8eb029f..17f4464 100644 --- a/src/nimblepkg/packageparser.nim +++ b/src/nimblepkg/packageparser.nim @@ -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.