e55e3f0f56ab4df21eb33e19569c295e7e5e71a4

Author
Marc Cornellà <hello@mcornella.com>
Committer
GitHub <noreply@github.com>
Date

Message

fix(systemadmin): handle error for no IPv6 route in `geteip` (#11458)

Diff

 1diff --git a/plugins/systemadmin/systemadmin.plugin.zsh b/plugins/systemadmin/systemadmin.plugin.zsh
 2index 9b5159ff19619804bb7e0da9cb280603d87857ff..7ce62bac134fa845ee39b8ecbf25b9edfeecd1b5 100644
 3--- a/plugins/systemadmin/systemadmin.plugin.zsh
 4+++ b/plugins/systemadmin/systemadmin.plugin.zsh
 5@@ -140,7 +140,13 @@ function d0() {
 6 # gather external ip address
 7 function geteip() {
 8     curl -s -S -4 https://icanhazip.com
 9-    curl -s -S -6 https://icanhazip.com
10+
11+    # handle case when there is no IPv6 external IP, which shows error
12+    # curl: (7) Couldn't connect to server
13+    curl -s -S -6 https://icanhazip.com 2>/dev/null
14+    local ret=$?
15+    (( ret == 7 )) && print -P -u2 "%F{red}error: no IPv6 route to host%f"
16+    return $ret
17 }
18 
19 # determine local IP address(es)