Raise an error if 'refresh' does not download anything successfully.
This commit is contained in:
parent
effbfbc6a1
commit
25a53eb4dc
1 changed files with 11 additions and 5 deletions
|
|
@ -59,6 +59,8 @@ proc refresh(options: Options) =
|
||||||
|
|
||||||
proc downloadList(list: PackageList, options: Options) =
|
proc downloadList(list: PackageList, options: Options) =
|
||||||
display("Downloading", list.name & " package list", priority = HighPriority)
|
display("Downloading", list.name & " package list", priority = HighPriority)
|
||||||
|
|
||||||
|
var lastError = ""
|
||||||
for i in 0 .. <list.urls.len:
|
for i in 0 .. <list.urls.len:
|
||||||
let url = list.urls[i]
|
let url = list.urls[i]
|
||||||
display("Trying", url)
|
display("Trying", url)
|
||||||
|
|
@ -75,21 +77,25 @@ proc refresh(options: Options) =
|
||||||
try:
|
try:
|
||||||
downloadFile(url, tempPath, proxy = getProxy(options))
|
downloadFile(url, tempPath, proxy = getProxy(options))
|
||||||
except:
|
except:
|
||||||
if i == <list.urls.len:
|
|
||||||
raise
|
|
||||||
let message = "Could not download: " & getCurrentExceptionMsg()
|
let message = "Could not download: " & getCurrentExceptionMsg()
|
||||||
display("Warning", message, Warning)
|
display("Warning", message, Warning)
|
||||||
|
lastError = message
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if not validatePackagesList(tempPath):
|
if not validatePackagesList(tempPath):
|
||||||
let message = "Downloaded packages.json file is invalid, discarding."
|
lastError = "Downloaded packages.json file is invalid"
|
||||||
display("Warning", message, Warning)
|
display("Warning", lastError & ", discarding.", Warning)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
copyFile(tempPath,
|
copyFile(tempPath,
|
||||||
options.getNimbleDir() / "packages_$1.json" % list.name.toLowerAscii())
|
options.getNimbleDir() / "packages_$1.json" % list.name.toLowerAscii())
|
||||||
display("Success", "Package list downloaded.", Success, HighPriority)
|
display("Success", "Package list downloaded.", Success, HighPriority)
|
||||||
|
lastError = ""
|
||||||
break
|
break
|
||||||
|
|
||||||
|
if lastError.len != 0:
|
||||||
|
raise newException(NimbleError, "Refresh failed\n" & lastError)
|
||||||
|
|
||||||
if parameter.len > 0:
|
if parameter.len > 0:
|
||||||
if parameter.isUrl:
|
if parameter.isUrl:
|
||||||
let cmdLine = PackageList(name: "commandline", urls: @[parameter])
|
let cmdLine = PackageList(name: "commandline", urls: @[parameter])
|
||||||
|
|
@ -1004,7 +1010,7 @@ proc doAction(options: Options) =
|
||||||
discard execHook(options, false)
|
discard execHook(options, false)
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
let error = ""
|
var error = ""
|
||||||
when defined(release):
|
when defined(release):
|
||||||
try:
|
try:
|
||||||
parseCmdLine().doAction()
|
parseCmdLine().doAction()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue