Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Dedicated error for unresolvable Git hostname
Browse files Browse the repository at this point in the history
  • Loading branch information
sysdevguru authored and hiddeco committed Feb 28, 2020
1 parent 8b3eb73 commit 65a36ff
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 2 additions & 0 deletions cmd/fluxctl/sync_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ func (opts *syncOpts) RunE(cmd *cobra.Command, args []string) error {
return fmt.Errorf("no git repository is configured")
case git.RepoReady:
break
case git.RepoUnreachable:
return fmt.Errorf("can not connect to git repository with URL %s\n\nFull error message: %v", gitConfig.Remote.URL, gitConfig.Error)
default:
if gitConfig.Error != "" {
return fmt.Errorf("git repository %s is not ready to sync\n\nFull error message: %v", gitConfig.Remote.URL, gitConfig.Error)
Expand Down
17 changes: 13 additions & 4 deletions pkg/git/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io/ioutil"
"os"
"strings"
"sync"

"context"
Expand Down Expand Up @@ -41,10 +42,11 @@ func (err NotReadyError) Error() string {
type GitRepoStatus string

const (
RepoNoConfig GitRepoStatus = "unconfigured" // configuration is empty
RepoNew GitRepoStatus = "new" // no attempt made to clone it yet
RepoCloned GitRepoStatus = "cloned" // has been read (cloned); no attempt made to write
RepoReady GitRepoStatus = "ready" // has been written to, so ready to sync
RepoNoConfig GitRepoStatus = "unconfigured" // configuration is empty
RepoNew GitRepoStatus = "new" // no attempt made to clone it yet
RepoCloned GitRepoStatus = "cloned" // has been read (cloned); no attempt made to write
RepoReady GitRepoStatus = "ready" // has been written to, so ready to sync
RepoUnreachable GitRepoStatus = "unreachable" // git repo is unreachable due to incorrect URL or DNS resolve failure
)

type Repo struct {
Expand Down Expand Up @@ -321,6 +323,10 @@ func (r *Repo) step(bg context.Context) bool {
r.setUnready(RepoCloned, ErrClonedOnly)
return true
}
if strings.Contains(strings.ToLower(err.Error()), "could not resolve hostname") {
r.setUnready(RepoUnreachable, err)
return false
}
dir = ""
os.RemoveAll(rootdir)
r.setUnready(RepoNew, err)
Expand Down Expand Up @@ -367,6 +373,9 @@ func (r *Repo) step(bg context.Context) bool {
r.refreshed()
return true

case RepoUnreachable:
return false

case RepoReady:
return false
}
Expand Down

0 comments on commit 65a36ff

Please sign in to comment.