Skip to content

Commit 965c6e5

Browse files
committed
fix: error when parsing hosts file
1 parent bf5dfd8 commit 965c6e5

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

daemon.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ func (d *Daemon) addVhost(binding string, w http.ResponseWriter) (chan string, *
246246

247247
err = addToHosts(vhost.Host)
248248
if err != nil {
249-
msg := fmt.Sprintf("[*] warning: failed to add %s to system hosts file", vhost.Host)
249+
msg := fmt.Sprintf("[*] warning: failed to add %s to system hosts file: %s\n", vhost.Host, err)
250250
fmt.Println(msg)
251251
logChan <- msg
252252
}

vhost.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,15 @@ func CreateVhost(input string, useTLS bool) (*Vhost, error) {
106106
func addToHosts(host string) error {
107107
hosts, errs := hostess.LoadHostfile()
108108
if len(errs) > 0 {
109-
return errs[0]
109+
realErrs := []error{}
110+
for _, err := range errs {
111+
if !strings.Contains(err.Error(), "duplicate") {
112+
realErrs = append(realErrs, err)
113+
}
114+
}
115+
if len(realErrs) > 0 {
116+
return realErrs[0]
117+
}
110118
}
111119

112120
hostname, err := hostess.NewHostname(host, "127.0.0.1", true)

0 commit comments

Comments
 (0)