Skip to content

Commit f6c72a9

Browse files
committed
return diags as err
1 parent 3aa740a commit f6c72a9

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

internal/backend/local/test.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -468,12 +468,8 @@ func (runner *TestFileRunner) run(run *moduletest.Run, file *moduletest.File, st
468468
return
469469
}
470470

471-
references, referenceDiags := run.GetReferences()
472-
run.Diagnostics = run.Diagnostics.Append(referenceDiags)
473-
if referenceDiags.HasErrors() {
474-
run.Status = moduletest.Error
475-
return
476-
}
471+
// already validated during static analysis
472+
references, _ := run.GetReferences()
477473

478474
variables, variableDiags := runner.GetVariables(run, references, true)
479475
run.Diagnostics = run.Diagnostics.Append(variableDiags)

internal/moduletest/graph/transform_test_run.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func (t *TestRunTransformer) Transform(g *terraform.Graph) error {
3333

3434
// Connect nodes based on dependencies
3535
if diags := t.connectDependencies(g, nodes); diags.HasErrors() {
36-
return tfdiags.NonFatalError{Diagnostics: diags}
36+
return tfdiags.DiagnosticsAsError{Diagnostics: diags}
3737
}
3838

3939
// Runs with the same state key inherently depend on each other, so we

internal/tfdiags/diagnostics.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func (diags Diagnostics) Append(new ...interface{}) Diagnostics {
5757
diags = append(diags, ti)
5858
case Diagnostics:
5959
diags = append(diags, ti...) // flatten
60-
case diagnosticsAsError:
60+
case DiagnosticsAsError:
6161
diags = diags.Append(ti.Diagnostics) // unwrap
6262
case NonFatalError:
6363
diags = diags.Append(ti.Diagnostics) // unwrap
@@ -111,7 +111,7 @@ func diagnosticsForError(err error) []Diagnostic {
111111

112112
// If we've wrapped a Diagnostics in an error then we'll unwrap
113113
// it and add it directly.
114-
var asErr diagnosticsAsError
114+
var asErr DiagnosticsAsError
115115
if errors.As(err, &asErr) {
116116
return asErr.Diagnostics
117117
}
@@ -206,7 +206,7 @@ func (diags Diagnostics) Err() error {
206206
if !diags.HasErrors() {
207207
return nil
208208
}
209-
return diagnosticsAsError{diags}
209+
return DiagnosticsAsError{diags}
210210
}
211211

212212
// ErrWithWarnings is similar to Err except that it will also return a non-nil
@@ -257,11 +257,12 @@ func (diags Diagnostics) Sort() {
257257
sort.Stable(sortDiagnostics(diags))
258258
}
259259

260-
type diagnosticsAsError struct {
260+
// DiagnosticsAsError embeds diagnostics, and satisfies the error interface.
261+
type DiagnosticsAsError struct {
261262
Diagnostics
262263
}
263264

264-
func (dae diagnosticsAsError) Error() string {
265+
func (dae DiagnosticsAsError) Error() string {
265266
diags := dae.Diagnostics
266267
switch {
267268
case len(diags) == 0:
@@ -291,7 +292,7 @@ func (dae diagnosticsAsError) Error() string {
291292

292293
// WrappedErrors is an implementation of errwrap.Wrapper so that an error-wrapped
293294
// diagnostics object can be picked apart by errwrap-aware code.
294-
func (dae diagnosticsAsError) WrappedErrors() []error {
295+
func (dae DiagnosticsAsError) WrappedErrors() []error {
295296
var errs []error
296297
for _, diag := range dae.Diagnostics {
297298
if wrapper, isErr := diag.(nativeError); isErr {

0 commit comments

Comments
 (0)