Skip to content

Commit

Permalink
Adjust error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
mszostok committed Aug 2, 2023
1 parent f96c299 commit 323f2d4
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ gen-grpc-resources:
# Generate plugins YAML index files for both all plugins and end-user ones.
gen-plugins-index: build-plugins
go run ./hack/gen-plugin-index.go -output-path ./plugins-dev-index.yaml
go run ./hack/gen-plugin-index.go -output-path ./plugins-index.yaml -plugin-name-filter 'kubectl|helm|kubernetes|prometheus|exec|doctor|keptn|github-events'
go run ./hack/gen-plugin-index.go -output-path ./plugins-index.yaml -plugin-name-filter 'kubectl|helm|kubernetes|prometheus|exec|doctor|keptn'

gen-docs-cli:
rm -f ./cmd/cli/docs/*
Expand Down
6 changes: 3 additions & 3 deletions internal/executor/flux/commands/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var f embed.FS
func LoadTemplates() ([]template.Template, error) {
dirs, err := f.ReadDir("store")
if err != nil {
return nil, err
return nil, fmt.Errorf("while reading store directory: %w", err)
}

var templates []template.Template
Expand All @@ -27,15 +27,15 @@ func LoadTemplates() ([]template.Template, error) {
}
file, err := f.ReadFile(filepath.Join("store", d.Name()))
if err != nil {
return nil, err
return nil, fmt.Errorf("while reading %q file: %w", d.Name(), err)
}

var cfg struct {
Templates []template.Template `yaml:"templates"`
}
err = yaml.Unmarshal(file, &cfg)
if err != nil {
return nil, fmt.Errorf("while unmarshaling file %q: %v", d.Name(), err)
return nil, fmt.Errorf("while unmarshaling %q file: %v", d.Name(), err)
}

templates = append(templates, cfg.Templates...)
Expand Down
14 changes: 7 additions & 7 deletions internal/executor/flux/diff_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (k *KustomizeDiffCmdService) runKustomizeDiff(ctx context.Context, diffCmd
pluginx.ExecuteCommandWorkingDir(workdir),
)
if err != nil {
k.log.WithError(err).WithField("command", kustomizeDiff.ToCmdString()).Error("failed to run command")
k.log.WithError(err).WithField("command", kustomizeDiff.ToCmdString()).Error("Failed to run command.")
return executor.ExecuteOutput{}, fmt.Errorf("while running command: %v", err)
}

Expand Down Expand Up @@ -302,11 +302,11 @@ func (*KustomizeDiffCmdService) runDiffCmd(ctx context.Context, in string, opts
func resolveGitHubRepoURL(ctx context.Context, logger logrus.FieldLogger, kubeConfigBytes []byte, ns string, name string) (string, error) {
scheme := runtime.NewScheme()
if err := kustomizev1.AddToScheme(scheme); err != nil {
return "", fmt.Errorf("failed to add Kustomize scheme: %w", err)
return "", fmt.Errorf("while adding Kustomize scheme: %w", err)
}

if err := sourcev1.AddToScheme(scheme); err != nil {
return "", fmt.Errorf("failed to add Source scheme: %w", err)
return "", fmt.Errorf("while adding Source scheme: %w", err)
}

kubeConfig, err := clientcmd.RESTConfigFromKubeConfig(kubeConfigBytes)
Expand All @@ -320,7 +320,7 @@ func resolveGitHubRepoURL(ctx context.Context, logger logrus.FieldLogger, kubeCo
Scheme: scheme,
})
if err != nil {
return "", fmt.Errorf("failed to create client: %w", err)
return "", fmt.Errorf("while creating client: %w", err)
}

// Resolve Kustomize
Expand All @@ -331,7 +331,7 @@ func resolveGitHubRepoURL(ctx context.Context, logger logrus.FieldLogger, kubeCo
}, &ks)

if err != nil {
return "", fmt.Errorf("failed to get Kustomization: %w", err)
return "", fmt.Errorf("while getting Kustomization: %w", err)
}

if ks.Spec.SourceRef.Kind != "GitRepository" {
Expand All @@ -351,7 +351,7 @@ func resolveGitHubRepoURL(ctx context.Context, logger logrus.FieldLogger, kubeCo
}, &git)

if err != nil {
return "", fmt.Errorf("failed to get GitRepository: %w", err)
return "", fmt.Errorf("while getting GitRepository: %w", err)
}

return git.Spec.URL, nil
Expand Down Expand Up @@ -392,7 +392,7 @@ func (k *KustomizeDiffCmdService) cloneResources(ctx context.Context, diff *Kust
// because we clone with --depth 1 we have issues as described here: https://github.com/cli/cli/issues/4287
_, err = pluginx.ExecuteCommand(ctx, `git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"`, gitSetupOpts...)
if err != nil {
return "", err
return "", fmt.Errorf("while setting up git repo: %w", err)
}

checkoutCmd := fmt.Sprintf("gh pr checkout %s", diff.GitHubRef)
Expand Down
2 changes: 1 addition & 1 deletion internal/executor/flux/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (d *Executor) Execute(ctx context.Context, in executor.ExecuteInput) (execu

templates, err := commands.LoadTemplates()
if err != nil {
return executor.ExecuteOutput{}, err
return executor.ExecuteOutput{}, fmt.Errorf("while loading templates: %w", err)
}

return x.NewRunner(log, renderer).RunWithTemplates(templates, state.ExtractSlackState(in.Context.SlackState), command, func() (string, error) {
Expand Down
1 change: 0 additions & 1 deletion pkg/pluginx/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ func (out ExecuteCommandOutput) CombinedOutput() string {

// ExecuteCommandWithEnvs is a simple wrapper around exec.CommandContext to simplify running a given
// command.
//
// Deprecated: Use ExecuteCommand(ctx, rawCmd, ExecuteCommandEnvs(envs)) instead.
func ExecuteCommandWithEnvs(ctx context.Context, rawCmd string, envs map[string]string) (string, error) {
out, err := ExecuteCommand(ctx, rawCmd, ExecuteCommandEnvs(envs))
Expand Down
4 changes: 2 additions & 2 deletions pkg/pluginx/command_opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ func ExecuteCommandDependencyDir(dir string) ExecuteCommandMutation {
}
}

// ExecuteCommandWorkingDir is a functions that sets the working directory of the command.
// ExecuteCommandWorkingDir is a function that sets the working directory of the command.
func ExecuteCommandWorkingDir(dir string) ExecuteCommandMutation {
return func(options *ExecuteCommandOptions) {
options.WorkDir = dir
}
}

// ExecuteCommandStdin is a functions that sets the stdin of the command.
// ExecuteCommandStdin is a function that sets the stdin of the command.
func ExecuteCommandStdin(in io.Reader) ExecuteCommandMutation {
return func(options *ExecuteCommandOptions) {
options.Stdin = in
Expand Down

0 comments on commit 323f2d4

Please sign in to comment.