Add hints for NimbleErrors which help the user fix them.
This commit is contained in:
parent
c0f2bd03b1
commit
8f34336e91
4 changed files with 23 additions and 7 deletions
|
|
@ -998,10 +998,10 @@ proc doAction(options: Options) =
|
||||||
|
|
||||||
let execResult = execTask(nimbleFile, options.action.command, options)
|
let execResult = execTask(nimbleFile, options.action.command, options)
|
||||||
if not execResult.success:
|
if not execResult.success:
|
||||||
writeHelp(false)
|
raiseNimbleError(msg = "Could not find task $1 in $2" %
|
||||||
|
[options.action.command, nimbleFile],
|
||||||
raise newException(NimbleError, "Could not find task $1 in $2" %
|
hint = "Run `nimble --help` and/or `nimble tasks` for" &
|
||||||
[options.action.command, nimbleFile])
|
" a list of possible commands.")
|
||||||
|
|
||||||
if execResult.command.normalize == "nop":
|
if execResult.command.normalize == "nop":
|
||||||
display("Warning:", "Using `setCommand 'nop'` is not necessary.", Warning,
|
display("Warning:", "Using `setCommand 'nop'` is not necessary.", Warning,
|
||||||
|
|
@ -1027,14 +1027,18 @@ proc doAction(options: Options) =
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
var error = ""
|
var error = ""
|
||||||
|
var hint = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
parseCmdLine().doAction()
|
parseCmdLine().doAction()
|
||||||
except NimbleError:
|
except NimbleError:
|
||||||
error = getCurrentExceptionMsg()
|
let err = (ref NimbleError)(getCurrentException())
|
||||||
|
error = err.msg
|
||||||
when not defined(release):
|
when not defined(release):
|
||||||
let stackTrace = getStackTrace(getCurrentException())
|
let stackTrace = getStackTrace(getCurrentException())
|
||||||
error = stackTrace & "\n\n" & error
|
error = stackTrace & "\n\n" & error
|
||||||
|
if not err.isNil:
|
||||||
|
hint = err.hint
|
||||||
except NimbleQuit:
|
except NimbleQuit:
|
||||||
nil
|
nil
|
||||||
finally:
|
finally:
|
||||||
|
|
@ -1043,4 +1047,6 @@ when isMainModule:
|
||||||
if error.len > 0:
|
if error.len > 0:
|
||||||
displayTip()
|
displayTip()
|
||||||
display("Error:", error, Error, HighPriority)
|
display("Error:", error, Error, HighPriority)
|
||||||
|
if hint.len > 0:
|
||||||
|
display("Hint:", hint, Warning, HighPriority)
|
||||||
quit(1)
|
quit(1)
|
||||||
|
|
|
||||||
|
|
@ -40,5 +40,10 @@ when not defined(nimscript):
|
||||||
## Same as quit(QuitSuccess), but allows cleanup.
|
## Same as quit(QuitSuccess), but allows cleanup.
|
||||||
NimbleQuit* = ref object of Exception
|
NimbleQuit* = ref object of Exception
|
||||||
|
|
||||||
|
proc raiseNimbleError*(msg: string, hint = "") =
|
||||||
|
var exc = newException(NimbleError, msg)
|
||||||
|
exc.hint = hint
|
||||||
|
raise exc
|
||||||
|
|
||||||
const
|
const
|
||||||
nimbleVersion* = "0.7.11"
|
nimbleVersion* = "0.7.11"
|
||||||
|
|
|
||||||
|
|
@ -241,6 +241,8 @@ proc getInstalledPkgs*(libsDir: string, options: Options):
|
||||||
const
|
const
|
||||||
readErrorMsg = "Installed package $1 v$2 is outdated or corrupt."
|
readErrorMsg = "Installed package $1 v$2 is outdated or corrupt."
|
||||||
validationErrorMsg = readErrorMsg & "\nPackage did not pass validation: $3"
|
validationErrorMsg = readErrorMsg & "\nPackage did not pass validation: $3"
|
||||||
|
hintMsg = "The corrupted package will need to be removed manually. To fix" &
|
||||||
|
" this error message, remove $1."
|
||||||
|
|
||||||
proc createErrorMsg(tmplt, path, msg: string): string =
|
proc createErrorMsg(tmplt, path, msg: string): string =
|
||||||
let (name, version) = getNameVersion(path)
|
let (name, version) = getNameVersion(path)
|
||||||
|
|
@ -261,14 +263,16 @@ proc getInstalledPkgs*(libsDir: string, options: Options):
|
||||||
except ValidationError:
|
except ValidationError:
|
||||||
let exc = (ref ValidationError)(getCurrentException())
|
let exc = (ref ValidationError)(getCurrentException())
|
||||||
exc.msg = createErrorMsg(validationErrorMsg, path, exc.msg)
|
exc.msg = createErrorMsg(validationErrorMsg, path, exc.msg)
|
||||||
|
exc.hint = hintMsg % path
|
||||||
if exc.warnInstalled:
|
if exc.warnInstalled:
|
||||||
display("Warning:", exc.msg, Warning, HighPriority)
|
display("Warning:", exc.msg, Warning, HighPriority)
|
||||||
else:
|
else:
|
||||||
raise exc
|
raise exc
|
||||||
except:
|
except:
|
||||||
let exc = getCurrentException()
|
|
||||||
let tmplt = readErrorMsg & "\nMore info: $3"
|
let tmplt = readErrorMsg & "\nMore info: $3"
|
||||||
exc.msg = createErrorMsg(tmplt, path, exc.msg)
|
let msg = createErrorMsg(tmplt, path, getCurrentException().msg)
|
||||||
|
var exc = newException(NimbleError, msg)
|
||||||
|
exc.hint = hintMsg % path
|
||||||
raise exc
|
raise exc
|
||||||
|
|
||||||
proc isNimScript*(nf: string, options: Options): bool =
|
proc isNimScript*(nf: string, options: Options): bool =
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ type
|
||||||
|
|
||||||
ParseVersionError* = object of ValueError
|
ParseVersionError* = object of ValueError
|
||||||
NimbleError* = object of Exception
|
NimbleError* = object of Exception
|
||||||
|
hint*: string
|
||||||
|
|
||||||
proc newVersion*(ver: string): Version = return Version(ver)
|
proc newVersion*(ver: string): Version = return Version(ver)
|
||||||
proc newSpecial*(spe: string): Special = return Special(spe)
|
proc newSpecial*(spe: string): Special = return Special(spe)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue