mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
vpm: make 'v install' more resilient to server failures
This commit is contained in:
parent
e03050014d
commit
c2e453fbb9
@ -129,36 +129,12 @@ fn vpm_install(module_names []string) {
|
|||||||
exit(2)
|
exit(2)
|
||||||
}
|
}
|
||||||
mut errors := 0
|
mut errors := 0
|
||||||
url := get_working_server_url()
|
|
||||||
for n in module_names {
|
for n in module_names {
|
||||||
name := n.trim_space()
|
name := n.trim_space()
|
||||||
modurl := url + '/jsmod/$name'
|
mod := get_module_meta_info(name) or {
|
||||||
r := http.get(modurl) or {
|
|
||||||
println('Http server did not respond to our request for ${modurl}.')
|
|
||||||
println('Error details: $err')
|
|
||||||
errors++
|
errors++
|
||||||
continue
|
println('Errors while retrieving meta data for module ${name}:')
|
||||||
}
|
println(err)
|
||||||
if r.status_code == 404 {
|
|
||||||
println('Skipping module "$name", since $url reported that "$name" does not exist.')
|
|
||||||
errors++
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if r.status_code != 200 {
|
|
||||||
println('Skipping module "$name", since $url responded with $r.status_code http status code. Please try again later.')
|
|
||||||
errors++
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
s := r.text
|
|
||||||
mod := json.decode(Mod,s) or {
|
|
||||||
errors++
|
|
||||||
println('Skipping module "$name", since its information is not in json format.')
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if ('' == mod.url || '' == mod.name) {
|
|
||||||
errors++
|
|
||||||
// a possible 404 error, which means a missing module?
|
|
||||||
println('Skipping module "$name", since it is missing name or url information.')
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
mut vcs := mod.vcs
|
mut vcs := mod.vcs
|
||||||
@ -464,3 +440,40 @@ fn verbose_println(s string) {
|
|||||||
println(s)
|
println(s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_module_meta_info(name string) ?Mod {
|
||||||
|
mut errors := []string
|
||||||
|
for server_url in default_vpm_server_urls {
|
||||||
|
modurl := server_url + '/jsmod/$name'
|
||||||
|
verbose_println('Retrieving module metadata from: $modurl ...')
|
||||||
|
r := http.get(modurl) or {
|
||||||
|
errors << 'Http server did not respond to our request for ${modurl}.'
|
||||||
|
errors << 'Error details: $err'
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if r.status_code == 404 {
|
||||||
|
errors << 'Skipping module "$name", since $server_url reported that "$name" does not exist.'
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if r.status_code != 200 {
|
||||||
|
errors << 'Skipping module "$name", since $server_url responded with $r.status_code http status code. Please try again later.'
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
s := r.text
|
||||||
|
if s.len > 0 && s[0] != `{` {
|
||||||
|
errors << 'Invalid json data'
|
||||||
|
errors << s.trim_space().limit(100) + '...'
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
mod := json.decode(Mod,s) or {
|
||||||
|
errors << 'Skipping module "$name", since its information is not in json format.'
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if ('' == mod.url || '' == mod.name) {
|
||||||
|
errors << 'Skipping module "$name", since it is missing name or url information.'
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return mod
|
||||||
|
}
|
||||||
|
return error(errors.join_lines())
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user