From f42ab00bb312248f2e7385c0e6e7a5743819c5a5 Mon Sep 17 00:00:00 2001 From: Dinos Kousidis Date: Sun, 19 Jan 2020 17:17:52 +0100 Subject: [PATCH] Add detailed error message in fluxctl sync * Extends v6.GitConfig to include `Error` field. * In case of `fluxctl sync` error, prints the `Error` field in the output. Signed-off-by: Dinos Kousidis --- cmd/fluxctl/sync_cmd.go | 5 ++++- pkg/api/v6/api.go | 1 + pkg/daemon/daemon.go | 8 +++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/cmd/fluxctl/sync_cmd.go b/cmd/fluxctl/sync_cmd.go index c3d3880f6..caf94d663 100644 --- a/cmd/fluxctl/sync_cmd.go +++ b/cmd/fluxctl/sync_cmd.go @@ -46,7 +46,10 @@ func (opts *syncOpts) RunE(cmd *cobra.Command, args []string) error { case git.RepoReady: break default: - return fmt.Errorf("git repository %s is not ready to sync (status: %s)", gitConfig.Remote.URL, string(gitConfig.Status)) + if gitConfig.Error != "" { + return fmt.Errorf("git repository %s is not ready to sync\n\nFull error message: %v", gitConfig.Remote.URL, gitConfig.Error) + } + return fmt.Errorf("git repository %s is not ready to sync", gitConfig.Remote.URL) } fmt.Fprintf(cmd.OutOrStderr(), "Synchronizing with %s\n", gitConfig.Remote.URL) diff --git a/pkg/api/v6/api.go b/pkg/api/v6/api.go index 7646f7621..734aa8951 100644 --- a/pkg/api/v6/api.go +++ b/pkg/api/v6/api.go @@ -58,6 +58,7 @@ type GitConfig struct { Remote GitRemoteConfig `json:"remote"` PublicSSHKey ssh.PublicKey `json:"publicSSHKey"` Status git.GitRepoStatus `json:"status"` + Error string `json:"errors"` } type Deprecated interface { diff --git a/pkg/daemon/daemon.go b/pkg/daemon/daemon.go index 777b2997f..78ae0352d 100644 --- a/pkg/daemon/daemon.go +++ b/pkg/daemon/daemon.go @@ -624,7 +624,12 @@ func (d *Daemon) GitRepoConfig(ctx context.Context, regenerate bool) (v6.GitConf origin := d.Repo.Origin() // Sanitize the URL before sharing it origin.URL = origin.SafeURL() - status, _ := d.Repo.Status() + status, err := d.Repo.Status() + gitConfigError := "" + if err != nil { + gitConfigError = err.Error() + } + path := "" if len(d.GitConfig.Paths) > 0 { path = strings.Join(d.GitConfig.Paths, ",") @@ -637,6 +642,7 @@ func (d *Daemon) GitRepoConfig(ctx context.Context, regenerate bool) (v6.GitConf }, PublicSSHKey: publicSSHKey, Status: status, + Error: gitConfigError, }, nil }