Skip to content

Commit

Permalink
Merge branch 'main' into 406-mach-composer-planapply--s-not-working-a…
Browse files Browse the repository at this point in the history
…nymore
  • Loading branch information
demeyerthom authored Dec 11, 2024
2 parents 6a1af59 + bfc5687 commit 25af154
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
3 changes: 3 additions & 0 deletions .changes/unreleased/Fixed-20241210-100157.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Fixed
body: Fixed logging returns when an error occurs
time: 2024-12-10T10:01:57.897306641+01:00
1 change: 0 additions & 1 deletion internal/cli/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ func PrintExitError(summary string, detail ...string) {
}

func HandleErr(err error) {
log.Error().Msgf("Error: %v\n", err)
var openApiErr *mccsdk.GenericOpenAPIError
if errors.As(err, &openApiErr) {
remoteErr := openApiErr.Model()
Expand Down
30 changes: 13 additions & 17 deletions internal/runner/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,6 @@ func (gr *GraphRunner) run(ctx context.Context, g *graph.Graph, f executorFunc,
errChan <- err
return
}

if err != nil {
errChan <- err
}
}(ctx, n)
}
wg.Wait()
Expand Down Expand Up @@ -172,7 +168,7 @@ func (gr *GraphRunner) TerraformApply(ctx context.Context, dg *graph.Graph, opts

out, err := terraform.Apply(ctx, n.Path(), aOpts...)
if err != nil {
return err
err = fmt.Errorf("failed to apply %s: %w", n.Identifier(), err)
}

if cli.OutputFromContext(ctx) == cli.OutputTypeJSON {
Expand All @@ -191,12 +187,12 @@ func (gr *GraphRunner) TerraformApply(ctx context.Context, dg *graph.Graph, opts
log.Ctx(ctx).Info().Msg(out)
}

log.Ctx(ctx).Info().Msgf("Storing new hash for %s", n.Path())
log.Ctx(ctx).Debug().Msgf("Storing new hash for %s", n.Path())
if err := gr.hash.Store(ctx, n); err != nil {
log.Ctx(ctx).Warn().Err(err).Msgf("Failed to store hash for %s", n.Identifier())
}

return nil
return err

}, opts.IgnoreChangeDetection); err != nil {
return err
Expand All @@ -220,11 +216,11 @@ func (gr *GraphRunner) TerraformValidate(ctx context.Context, dg *graph.Graph) e

out, err = terraform.Validate(ctx, n.Path(), vOpts...)
if err != nil {
return err
err = fmt.Errorf("failed to validate %s: %w", n.Identifier(), err)
}
log.Ctx(ctx).Info().Msg(out)

return nil
return err
}, true)
}

Expand Down Expand Up @@ -261,7 +257,7 @@ func (gr *GraphRunner) TerraformPlan(ctx context.Context, dg *graph.Graph, opts

out, err := terraform.Plan(ctx, n.Path(), pOpts...)
if err != nil {
return err
err = fmt.Errorf("failed to plan %s: %w", n.Identifier(), err)
}

if cli.OutputFromContext(ctx) == cli.OutputTypeJSON {
Expand All @@ -280,7 +276,7 @@ func (gr *GraphRunner) TerraformPlan(ctx context.Context, dg *graph.Graph, opts
log.Ctx(ctx).Info().Msg(out)
}

return nil
return err
}, opts.IgnoreChangeDetection); err != nil {
return err
}
Expand All @@ -296,10 +292,10 @@ func (gr *GraphRunner) TerraformProxy(ctx context.Context, dg *graph.Graph, opts

out, err := utils.RunTerraform(ctx, n.Path(), opts.Command...)
if err != nil {
return err
err = fmt.Errorf("failed to proxy %s: %w", n.Identifier(), err)
}
log.Ctx(ctx).Info().Msg(out)
return nil
return err
}, opts.IgnoreChangeDetection); err != nil {
return err
}
Expand Down Expand Up @@ -330,7 +326,7 @@ func (gr *GraphRunner) TerraformShow(ctx context.Context, dg *graph.Graph, opts

out, err := terraform.Show(ctx, n.Path(), sOpts...)
if err != nil {
return err
err = fmt.Errorf("failed to show %s: %w", n.Identifier(), err)
}

if cli.OutputFromContext(ctx) == cli.OutputTypeJSON {
Expand All @@ -348,7 +344,7 @@ func (gr *GraphRunner) TerraformShow(ctx context.Context, dg *graph.Graph, opts
} else {
log.Ctx(ctx).Info().Msg(out)
}
return nil
return err
}, opts.IgnoreChangeDetection); err != nil {
return err
}
Expand All @@ -360,10 +356,10 @@ func (gr *GraphRunner) TerraformInit(ctx context.Context, dg *graph.Graph) error
if err := gr.run(ctx, dg, func(ctx context.Context, n graph.Node) error {
out, err := terraform.Init(ctx, n.Path())
if err != nil {
return err
err = fmt.Errorf("failed to init %s: %w", n.Identifier(), err)
}
log.Ctx(ctx).Info().Msg(out)
return nil
return err
}, true); err != nil {
return err
}
Expand Down
5 changes: 2 additions & 3 deletions internal/utils/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func RunInteractive(ctx context.Context, command string, cwd string, args ...str
stdOut := new(bytes.Buffer)

cmd.Stdin = os.Stdin
cmd.Stderr = os.Stderr
cmd.Stderr = stdOut
cmd.Stdout = stdOut

err := cmd.Start()
Expand All @@ -48,8 +48,7 @@ func RunInteractive(ctx context.Context, command string, cwd string, args ...str

case err := <-done:
if err != nil {
//TODO: should we return the buffer here also?
return "", fmt.Errorf("command (%s) failed: %w (args: %s , cwd: %s)", command, err, strings.Join(args, " "), cwd)
return stdOut.String(), fmt.Errorf("command (%s) failed: %w (args: %s , cwd: %s)", command, err, strings.Join(args, " "), cwd)
}
}

Expand Down

0 comments on commit 25af154

Please sign in to comment.