From 764f8ea608017a1b15ef3777493b756384f05d16 Mon Sep 17 00:00:00 2001 From: i4k Date: Mon, 16 Sep 2024 23:19:45 +0100 Subject: [PATCH] chore: improve warning message to contain offended stack. In case a stack contains invalid paths in after/before/wants/wanted_by the offended stack needs to be in the warning output. Signed-off-by: i4k --- e2etests/core/run_test.go | 6 +++--- hcl/stack.tm.hcl | 1 + run/order.go | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/e2etests/core/run_test.go b/e2etests/core/run_test.go index 92022d76f9..cacc3746b1 100644 --- a/e2etests/core/run_test.go +++ b/e2etests/core/run_test.go @@ -79,7 +79,7 @@ func TestCLIRunOrder(t *testing.T) { Stdout: nljoin( `/stack`, ), - StderrRegex: "Warning: Stack references invalid path in 'after' attribute", + StderrRegex: "Warning: Stack /stack references invalid path in 'after' attribute", }, }, { @@ -91,7 +91,7 @@ func TestCLIRunOrder(t *testing.T) { Stdout: nljoin( `/stack`, ), - StderrRegex: "Warning: Stack references invalid path in 'after' attribute", + StderrRegex: "Warning: Stack /stack references invalid path in 'after' attribute", }, }, { @@ -1501,7 +1501,7 @@ func TestRunWantedBy(t *testing.T) { "/stacks/stack-b", ), StderrRegexes: []string{ - "Stack references invalid path in 'wanted_by' attribute", + "Stack /stacks/stack-a references invalid path in 'wanted_by' attribute", "no such file or directory", }, }, diff --git a/hcl/stack.tm.hcl b/hcl/stack.tm.hcl index d08c1b81da..a14a3bda0d 100644 --- a/hcl/stack.tm.hcl +++ b/hcl/stack.tm.hcl @@ -6,4 +6,5 @@ stack { description = "package hcl // import \"github.com/terramate-io/terramate/hcl\"\n\nPackage hcl provides parsing functionality for Terramate HCL configuration.\nIt also provides printing and formatting for Terramate configuration.\n\nconst ErrHCLSyntax errors.Kind = \"HCL syntax error\" ...\nconst ErrScriptNoLabels errors.Kind = \"terramate schema error: (script): must provide at least one label\" ...\nconst SharingIsCaringExperimentName = \"outputs-sharing\"\nconst StackBlockType = \"stack\"\nfunc IsRootConfig(rootdir string) (bool, error)\nfunc MatchAnyGlob(globs []glob.Glob, s string) bool\nfunc PrintConfig(w io.Writer, cfg Config) error\nfunc PrintImports(w io.Writer, imports []string) error\nfunc ValueAsStringList(val cty.Value) ([]string, error)\ntype AssertConfig struct{ ... }\ntype ChangeDetectionConfig struct{ ... }\ntype CloudConfig struct{ ... }\ntype Command ast.Attribute\n func NewScriptCommand(attr ast.Attribute) *Command\ntype Commands ast.Attribute\n func NewScriptCommands(attr ast.Attribute) *Commands\ntype Config struct{ ... }\n func NewConfig(dir string) (Config, error)\n func ParseDir(root string, dir string, experiments ...string) (Config, error)\ntype Evaluator interface{ ... }\ntype GenFileBlock struct{ ... }\ntype GenHCLBlock struct{ ... }\ntype GenerateConfig struct{ ... }\ntype GenerateRootConfig struct{ ... }\ntype GitConfig struct{ ... }\n func NewGitConfig() *GitConfig\ntype Input struct{ ... }\ntype Inputs []Input\ntype ManifestConfig struct{ ... }\ntype ManifestDesc struct{ ... }\ntype OptionalCheck int\n const CheckIsUnset OptionalCheck = iota ...\n func ToOptionalCheck(v bool) OptionalCheck\ntype Output struct{ ... }\ntype Outputs []Output\ntype RawConfig struct{ ... }\n func NewCustomRawConfig(handlers map[string]mergeHandler) RawConfig\n func NewTopLevelRawConfig() RawConfig\ntype RootConfig struct{ ... }\ntype RunConfig struct{ ... }\n func NewRunConfig() *RunConfig\ntype RunEnv struct{ ... }\ntype Script struct{ ... }\ntype ScriptJob struct{ ... }\ntype SharingBackend struct{ ... }\ntype SharingBackendType int\n const TerraformSharingBackend SharingBackendType = iota + 1\ntype SharingBackends []SharingBackend\ntype Stack struct{ ... }\ntype StackFilterConfig struct{ ... }\ntype TargetsConfig struct{ ... }\ntype TerragruntChangeDetectionEnabledOption int\n const TerragruntAutoOption TerragruntChangeDetectionEnabledOption = iota ...\ntype TerragruntConfig struct{ ... }\ntype Terramate struct{ ... }\ntype TerramateParser struct{ ... }\n func NewStrictTerramateParser(rootdir string, dir string, experiments ...string) (*TerramateParser, error)\n func NewTerramateParser(rootdir string, dir string, experiments ...string) (*TerramateParser, error)\ntype VendorConfig struct{ ... }" tags = ["golang", "hcl"] id = "dd11014a-a1bb-4f1c-99da-8f6d188d36d1" + after = ["/e2etess"] } diff --git a/run/order.go b/run/order.go index 5aa485cd11..b69e55e7f8 100644 --- a/run/order.go +++ b/run/order.go @@ -218,12 +218,12 @@ func BuildDAG( st, err := os.Stat(abspath) if err != nil { printer.Stderr.WarnWithDetails( - fmt.Sprintf("Stack references invalid path in '%s' attribute", fieldname), + fmt.Sprintf("Stack %s references invalid path in '%s' attribute", s.Dir, fieldname), err, ) } else if !st.IsDir() { printer.Stderr.WarnWithDetails( - fmt.Sprintf("Stack references invalid path in '%s' attribute", fieldname), + fmt.Sprintf("Stack %s references invalid path in '%s' attribute", s.Dir, fieldname), errors.E("Path %s is not a directory", pathstr), ) } else {