Skip to content

Commit 8c6591b

Browse files
authored
Improve error stack trace. Add --stack flag to atmos describe affected command. Improve atmos.Component template function (#714)
* updates * Print stack trace on error only in log level `Trace` * Don't process Terraform output for abstract and disabled components in `atmos.Component` template function * Don't process Terraform output for abstract and disabled components in `atmos.Component` template function * Add `--stack` flag to `atmos describe affected` command * Add `--stack` flag to `atmos describe affected` command * Add `--stack` flag to `atmos describe affected` command * Add `--stack` flag to `atmos describe affected` command * Add `--stack` flag to `atmos describe affected` command
1 parent 7c41087 commit 8c6591b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+444
-548
lines changed

cmd/atlantis_generate_repo_config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"github.com/cloudposse/atmos/pkg/schema"
45
"github.com/spf13/cobra"
56

67
e "github.com/cloudposse/atmos/internal/exec"
@@ -19,7 +20,7 @@ var atlantisGenerateRepoConfigCmd = &cobra.Command{
1920

2021
err := e.ExecuteAtlantisGenerateRepoConfigCmd(cmd, args)
2122
if err != nil {
22-
u.LogErrorAndExit(err)
23+
u.LogErrorAndExit(schema.CliConfiguration{}, err)
2324
}
2425
},
2526
}

cmd/aws_eks_update_kubeconfig.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"github.com/spf13/cobra"
55

66
e "github.com/cloudposse/atmos/internal/exec"
7+
"github.com/cloudposse/atmos/pkg/schema"
78
u "github.com/cloudposse/atmos/pkg/utils"
89
)
910

@@ -36,7 +37,7 @@ See https://docs.aws.amazon.com/cli/latest/reference/eks/update-kubeconfig.html
3637
Run: func(cmd *cobra.Command, args []string) {
3738
err := e.ExecuteAwsEksUpdateKubeconfigCommand(cmd, args)
3839
if err != nil {
39-
u.LogErrorAndExit(err)
40+
u.LogErrorAndExit(schema.CliConfiguration{}, err)
4041
}
4142
},
4243
}

cmd/cmd_utils.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,13 @@ func processCommandAliases(
121121
Run: func(cmd *cobra.Command, args []string) {
122122
err := cmd.ParseFlags(args)
123123
if err != nil {
124-
u.LogErrorAndExit(err)
124+
u.LogErrorAndExit(cliConfig, err)
125125
}
126126

127127
commandToRun := fmt.Sprintf("%s %s %s", os.Args[0], aliasCmd, strings.Join(args, " "))
128128
err = e.ExecuteShell(cliConfig, commandToRun, commandToRun, ".", nil, false)
129129
if err != nil {
130-
u.LogErrorAndExit(err)
130+
u.LogErrorAndExit(cliConfig, err)
131131
}
132132
},
133133
}
@@ -153,7 +153,7 @@ func preCustomCommand(
153153

154154
if len(args) != len(commandConfig.Arguments) {
155155
err = fmt.Errorf("invalid number of arguments, %d argument(s) required", len(commandConfig.Arguments))
156-
u.LogErrorAndExit(err)
156+
u.LogErrorAndExit(schema.CliConfiguration{}, err)
157157
}
158158

159159
// no "steps" means a sub command should be specified
@@ -203,7 +203,7 @@ func executeCustomCommand(
203203
if fl.Type == "" || fl.Type == "string" {
204204
providedFlag, err := flags.GetString(fl.Name)
205205
if err != nil {
206-
u.LogErrorAndExit(err)
206+
u.LogErrorAndExit(cliConfig, err)
207207
}
208208
flagsData[fl.Name] = providedFlag
209209
}
@@ -221,27 +221,27 @@ func executeCustomCommand(
221221
// Process Go templates in the command's 'component_config.component'
222222
component, err := e.ProcessTmpl(fmt.Sprintf("component-config-component-%d", i), commandConfig.ComponentConfig.Component, data, false)
223223
if err != nil {
224-
u.LogErrorAndExit(err)
224+
u.LogErrorAndExit(cliConfig, err)
225225
}
226226
if component == "" || component == "<no value>" {
227-
u.LogErrorAndExit(fmt.Errorf("the command defines an invalid 'component_config.component: %s' in '%s'",
227+
u.LogErrorAndExit(cliConfig, fmt.Errorf("the command defines an invalid 'component_config.component: %s' in '%s'",
228228
commandConfig.ComponentConfig.Component, cfg.CliConfigFileName))
229229
}
230230

231231
// Process Go templates in the command's 'component_config.stack'
232232
stack, err := e.ProcessTmpl(fmt.Sprintf("component-config-stack-%d", i), commandConfig.ComponentConfig.Stack, data, false)
233233
if err != nil {
234-
u.LogErrorAndExit(err)
234+
u.LogErrorAndExit(cliConfig, err)
235235
}
236236
if stack == "" || stack == "<no value>" {
237-
u.LogErrorAndExit(fmt.Errorf("the command defines an invalid 'component_config.stack: %s' in '%s'",
237+
u.LogErrorAndExit(cliConfig, fmt.Errorf("the command defines an invalid 'component_config.stack: %s' in '%s'",
238238
commandConfig.ComponentConfig.Stack, cfg.CliConfigFileName))
239239
}
240240

241241
// Get the config for the component in the stack
242242
componentConfig, err := e.ExecuteDescribeComponent(component, stack, true)
243243
if err != nil {
244-
u.LogErrorAndExit(err)
244+
u.LogErrorAndExit(cliConfig, err)
245245
}
246246
data["ComponentConfig"] = componentConfig
247247
}
@@ -258,29 +258,29 @@ func executeCustomCommand(
258258
err = fmt.Errorf("either 'value' or 'valueCommand' can be specified for the ENV var, but not both.\n"+
259259
"Custom command '%s %s' defines 'value=%s' and 'valueCommand=%s' for the ENV var '%s'",
260260
parentCommand.Name(), commandConfig.Name, value, valCommand, key)
261-
u.LogErrorAndExit(err)
261+
u.LogErrorAndExit(cliConfig, err)
262262
}
263263

264264
// If the command to get the value for the ENV var is provided, execute it
265265
if valCommand != "" {
266266
valCommandName := fmt.Sprintf("env-var-%s-valcommand", key)
267267
res, err := e.ExecuteShellAndReturnOutput(cliConfig, valCommand, valCommandName, ".", nil, false)
268268
if err != nil {
269-
u.LogErrorAndExit(err)
269+
u.LogErrorAndExit(cliConfig, err)
270270
}
271271
value = strings.TrimRight(res, "\r\n")
272272
} else {
273273
// Process Go templates in the values of the command's ENV vars
274274
value, err = e.ProcessTmpl(fmt.Sprintf("env-var-%d", i), value, data, false)
275275
if err != nil {
276-
u.LogErrorAndExit(err)
276+
u.LogErrorAndExit(cliConfig, err)
277277
}
278278
}
279279

280280
envVarsList = append(envVarsList, fmt.Sprintf("%s=%s", key, value))
281281
err = os.Setenv(key, value)
282282
if err != nil {
283-
u.LogErrorAndExit(err)
283+
u.LogErrorAndExit(cliConfig, err)
284284
}
285285
}
286286

@@ -295,14 +295,14 @@ func executeCustomCommand(
295295
// Steps support Go templates and have access to {{ .ComponentConfig.xxx.yyy.zzz }} Go template variables
296296
commandToRun, err := e.ProcessTmpl(fmt.Sprintf("step-%d", i), step, data, false)
297297
if err != nil {
298-
u.LogErrorAndExit(err)
298+
u.LogErrorAndExit(cliConfig, err)
299299
}
300300

301301
// Execute the command step
302302
commandName := fmt.Sprintf("%s-step-%d", commandConfig.Name, i)
303303
err = e.ExecuteShell(cliConfig, commandToRun, commandName, ".", envVarsList, false)
304304
if err != nil {
305-
u.LogErrorAndExit(err)
305+
u.LogErrorAndExit(cliConfig, err)
306306
}
307307
}
308308
}
@@ -326,7 +326,7 @@ func cloneCommand(orig *schema.Command) (*schema.Command, error) {
326326
func checkAtmosConfig() {
327327
cliConfig, err := cfg.InitCliConfig(schema.ConfigAndStacksInfo{}, false)
328328
if err != nil {
329-
u.LogErrorAndExit(err)
329+
u.LogErrorAndExit(cliConfig, err)
330330
}
331331

332332
atmosConfigExists, err := u.IsDirectory(cliConfig.StacksBaseAbsolutePath)
@@ -345,7 +345,7 @@ func printMessageForMissingAtmosConfig(cliConfig schema.CliConfiguration) {
345345
fmt.Println()
346346
err := tuiUtils.PrintStyledText("ATMOS")
347347
if err != nil {
348-
u.LogErrorAndExit(err)
348+
u.LogErrorAndExit(cliConfig, err)
349349
}
350350

351351
if cliConfig.Default {

cmd/completion.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"github.com/cloudposse/atmos/pkg/schema"
45
"os"
56

67
"github.com/spf13/cobra"
@@ -30,7 +31,7 @@ var completionCmd = &cobra.Command{
3031
}
3132

3233
if err != nil {
33-
u.LogErrorAndExit(err)
34+
u.LogErrorAndExit(schema.CliConfiguration{}, err)
3435
}
3536
},
3637
}

cmd/describe_affected.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"github.com/cloudposse/atmos/pkg/schema"
45
"github.com/spf13/cobra"
56

67
e "github.com/cloudposse/atmos/internal/exec"
@@ -19,7 +20,7 @@ var describeAffectedCmd = &cobra.Command{
1920

2021
err := e.ExecuteDescribeAffectedCmd(cmd, args)
2122
if err != nil {
22-
u.LogErrorAndExit(err)
23+
u.LogErrorAndExit(schema.CliConfiguration{}, err)
2324
}
2425
},
2526
}
@@ -39,6 +40,7 @@ func init() {
3940
describeAffectedCmd.PersistentFlags().Bool("include-dependents", false, "Include the dependent components and stacks: atmos describe affected --include-dependents=true")
4041
describeAffectedCmd.PersistentFlags().Bool("include-settings", false, "Include the 'settings' section for each affected component: atmos describe affected --include-settings=true")
4142
describeAffectedCmd.PersistentFlags().Bool("upload", false, "Upload the affected components and stacks to a specified HTTP endpoint: atmos describe affected --upload=true")
43+
describeAffectedCmd.PersistentFlags().StringP("stack", "s", "", "atmos describe affected -s <stack>")
4244
describeAffectedCmd.PersistentFlags().Bool("clone-target-ref", false, "Clone the target reference with which to compare the current branch: atmos describe affected --clone-target-ref=true\n"+
4345
"If set to 'false' (default), the target reference will be checked out instead\n"+
4446
"This requires that the target reference is already cloned by Git, and the information about it exists in the '.git' directory")

cmd/describe_component.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"github.com/cloudposse/atmos/pkg/schema"
45
"github.com/spf13/cobra"
56

67
e "github.com/cloudposse/atmos/internal/exec"
@@ -19,7 +20,7 @@ var describeComponentCmd = &cobra.Command{
1920

2021
err := e.ExecuteDescribeComponentCmd(cmd, args)
2122
if err != nil {
22-
u.LogErrorAndExit(err)
23+
u.LogErrorAndExit(schema.CliConfiguration{}, err)
2324
}
2425
},
2526
}
@@ -33,7 +34,7 @@ func init() {
3334

3435
err := describeComponentCmd.MarkPersistentFlagRequired("stack")
3536
if err != nil {
36-
u.LogErrorAndExit(err)
37+
u.LogErrorAndExit(schema.CliConfiguration{}, err)
3738
}
3839

3940
describeCmd.AddCommand(describeComponentCmd)

cmd/describe_config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"github.com/spf13/cobra"
55

66
e "github.com/cloudposse/atmos/internal/exec"
7+
"github.com/cloudposse/atmos/pkg/schema"
78
u "github.com/cloudposse/atmos/pkg/utils"
89
)
910

@@ -16,7 +17,7 @@ var describeConfigCmd = &cobra.Command{
1617
Run: func(cmd *cobra.Command, args []string) {
1718
err := e.ExecuteDescribeConfigCmd(cmd, args)
1819
if err != nil {
19-
u.LogErrorAndExit(err)
20+
u.LogErrorAndExit(schema.CliConfiguration{}, err)
2021
}
2122
},
2223
}

cmd/describe_dependents.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"github.com/cloudposse/atmos/pkg/schema"
45
"github.com/spf13/cobra"
56

67
e "github.com/cloudposse/atmos/internal/exec"
@@ -20,7 +21,7 @@ var describeDependentsCmd = &cobra.Command{
2021

2122
err := e.ExecuteDescribeDependentsCmd(cmd, args)
2223
if err != nil {
23-
u.LogErrorAndExit(err)
24+
u.LogErrorAndExit(schema.CliConfiguration{}, err)
2425
}
2526
},
2627
}
@@ -34,7 +35,7 @@ func init() {
3435

3536
err := describeDependentsCmd.MarkPersistentFlagRequired("stack")
3637
if err != nil {
37-
u.LogErrorAndExit(err)
38+
u.LogErrorAndExit(schema.CliConfiguration{}, err)
3839
}
3940

4041
describeCmd.AddCommand(describeDependentsCmd)

cmd/describe_stacks.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"github.com/spf13/cobra"
55

66
e "github.com/cloudposse/atmos/internal/exec"
7+
"github.com/cloudposse/atmos/pkg/schema"
78
u "github.com/cloudposse/atmos/pkg/utils"
89
)
910

@@ -19,7 +20,7 @@ var describeStacksCmd = &cobra.Command{
1920

2021
err := e.ExecuteDescribeStacksCmd(cmd, args)
2122
if err != nil {
22-
u.LogErrorAndExit(err)
23+
u.LogErrorAndExit(schema.CliConfiguration{}, err)
2324
}
2425
},
2526
}

cmd/describe_workflows.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"github.com/spf13/cobra"
55

66
e "github.com/cloudposse/atmos/internal/exec"
7+
"github.com/cloudposse/atmos/pkg/schema"
78
u "github.com/cloudposse/atmos/pkg/utils"
89
)
910

@@ -23,7 +24,7 @@ var describeWorkflowsCmd = &cobra.Command{
2324
Run: func(cmd *cobra.Command, args []string) {
2425
err := e.ExecuteDescribeWorkflowsCmd(cmd, args)
2526
if err != nil {
26-
u.LogErrorAndExit(err)
27+
u.LogErrorAndExit(schema.CliConfiguration{}, err)
2728
}
2829
},
2930
}

0 commit comments

Comments
 (0)