mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-11 08:32:19 -06:00
Fix repetitive diagnosis output in init response (#1890)
Signed-off-by: buraksenn <buraksenb@gmail.com>
This commit is contained in:
parent
1741058111
commit
7a02fad996
@ -292,8 +292,7 @@ func (c *InitCommand) Run(args []string) int {
|
|||||||
|
|
||||||
// Now, we can check the diagnostics from the early configuration and the
|
// Now, we can check the diagnostics from the early configuration and the
|
||||||
// backend.
|
// backend.
|
||||||
diags = diags.Append(earlyConfDiags)
|
diags = diags.Append(earlyConfDiags.StrictDeduplicateMerge(backDiags))
|
||||||
diags = diags.Append(backDiags)
|
|
||||||
if earlyConfDiags.HasErrors() {
|
if earlyConfDiags.HasErrors() {
|
||||||
c.Ui.Error(strings.TrimSpace(errInitConfigError))
|
c.Ui.Error(strings.TrimSpace(errInitConfigError))
|
||||||
c.showDiagnostics(diags)
|
c.showDiagnostics(diags)
|
||||||
|
@ -2995,6 +2995,33 @@ func TestInit_moduleVersion(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestInit_invalidExtraLabel(t *testing.T) {
|
||||||
|
td := t.TempDir()
|
||||||
|
testCopyDir(t, testFixturePath("init-syntax-invalid-extra-label"), td)
|
||||||
|
defer testChdir(t, td)()
|
||||||
|
|
||||||
|
ui := cli.NewMockUi()
|
||||||
|
view, _ := testView(t)
|
||||||
|
m := Meta{
|
||||||
|
Ui: ui,
|
||||||
|
View: view,
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &InitCommand{
|
||||||
|
Meta: m,
|
||||||
|
}
|
||||||
|
|
||||||
|
if code := c.Run(nil); code == 0 {
|
||||||
|
t.Fatalf("succeeded, but was expecting error\nstdout:\n%s\nstderr:\n%s", ui.OutputWriter, ui.ErrorWriter)
|
||||||
|
}
|
||||||
|
|
||||||
|
errStr := ui.ErrorWriter.String()
|
||||||
|
splitted := strings.Split(errStr, "Error: Unsupported block type")
|
||||||
|
if len(splitted) != 2 {
|
||||||
|
t.Fatalf("want exactly one unsupported block type errors but got: %d\nstderr:\n%s\n\nstdout:\n%s", len(splitted)-1, errStr, ui.OutputWriter.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// newMockProviderSource is a helper to succinctly construct a mock provider
|
// newMockProviderSource is a helper to succinctly construct a mock provider
|
||||||
// source that contains a set of packages matching the given provider versions
|
// source that contains a set of packages matching the given provider versions
|
||||||
// that are available for installation (from temporary local files).
|
// that are available for installation (from temporary local files).
|
||||||
|
10
internal/command/testdata/init-syntax-invalid-extra-label/main.tf
vendored
Normal file
10
internal/command/testdata/init-syntax-invalid-extra-label/main.tf
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
terraform {
|
||||||
|
extra_label{
|
||||||
|
required_providers {
|
||||||
|
azurerm = {
|
||||||
|
source = "hashicorp/azurerm"
|
||||||
|
version = "~> 3.0.2"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -58,11 +58,19 @@ type Description struct {
|
|||||||
Detail string
|
Detail string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d Description) Equal(other Description) bool {
|
||||||
|
return d.Address == other.Address && d.Summary == other.Summary && d.Detail == other.Detail
|
||||||
|
}
|
||||||
|
|
||||||
type Source struct {
|
type Source struct {
|
||||||
Subject *SourceRange
|
Subject *SourceRange
|
||||||
Context *SourceRange
|
Context *SourceRange
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s Source) Equal(other Source) bool {
|
||||||
|
return s.Subject.Equal(other.Subject) && s.Context.Equal(other.Context)
|
||||||
|
}
|
||||||
|
|
||||||
type FromExpr struct {
|
type FromExpr struct {
|
||||||
Expression hcl.Expression
|
Expression hcl.Expression
|
||||||
EvalContext *hcl.EvalContext
|
EvalContext *hcl.EvalContext
|
||||||
|
@ -101,6 +101,23 @@ func (diags Diagnostics) Append(new ...interface{}) Diagnostics {
|
|||||||
return diags
|
return diags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (diags Diagnostics) StrictDeduplicateMerge(other Diagnostics) Diagnostics {
|
||||||
|
if len(diags) == 0 {
|
||||||
|
return other
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, d := range diags {
|
||||||
|
for _, o := range other {
|
||||||
|
isEqual := d.Description().Equal(o.Description()) && d.Severity() == o.Severity() && d.Source().Equal(o.Source())
|
||||||
|
if DoNotConsolidateDiagnostic(d) || DoNotConsolidateDiagnostic(o) || !isEqual {
|
||||||
|
diags = append(diags, o)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return diags
|
||||||
|
}
|
||||||
|
|
||||||
// HasErrors returns true if any of the diagnostics in the list have
|
// HasErrors returns true if any of the diagnostics in the list have
|
||||||
// a severity of Error.
|
// a severity of Error.
|
||||||
func (diags Diagnostics) HasErrors() bool {
|
func (diags Diagnostics) HasErrors() bool {
|
||||||
|
@ -16,10 +16,22 @@ type SourceRange struct {
|
|||||||
Start, End SourcePos
|
Start, End SourcePos
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *SourceRange) Equal(other *SourceRange) bool {
|
||||||
|
if r == nil || other == nil {
|
||||||
|
return r == other
|
||||||
|
}
|
||||||
|
|
||||||
|
return r.Filename == other.Filename && r.Start.Equal(other.Start) && r.End.Equal(other.End)
|
||||||
|
}
|
||||||
|
|
||||||
type SourcePos struct {
|
type SourcePos struct {
|
||||||
Line, Column, Byte int
|
Line, Column, Byte int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p SourcePos) Equal(other SourcePos) bool {
|
||||||
|
return p.Line == other.Line && p.Column == other.Column && p.Byte == other.Byte
|
||||||
|
}
|
||||||
|
|
||||||
// StartString returns a string representation of the start of the range,
|
// StartString returns a string representation of the start of the range,
|
||||||
// including the filename and the line and column numbers.
|
// including the filename and the line and column numbers.
|
||||||
func (r SourceRange) StartString() string {
|
func (r SourceRange) StartString() string {
|
||||||
|
Loading…
Reference in New Issue
Block a user