-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
diag: Add WithPath function and remove AttributeErrorDiagnostic and A…
…ttributeWarningDiagnostic types (#219) Reference: #169 Instead of embedding path information directly in diagnostic types, it can instead be handled as a wrapper. This encourages a separation of concerns and simplifies implementations. Future enhancements, such as type checking wrapped diagnostics in #218, can enable advanced use cases.
- Loading branch information
Showing
23 changed files
with
165 additions
and
253 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
```release-note:breaking-change | ||
diag: The `AttributeErrorDiagnostic` and `AttributeWarningDiagnostic` types have been removed. Any usage can be replaced with `DiagnosticWithPath`. | ||
``` | ||
|
||
```release-note:enhancement | ||
diag: Added `WithPath()` function to wrap or overwrite diagnostic path information. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package diag | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-go/tftypes" | ||
) | ||
|
||
var _ DiagnosticWithPath = withPath{} | ||
|
||
// withPath wraps a diagnostic with path information. | ||
type withPath struct { | ||
Diagnostic | ||
|
||
path *tftypes.AttributePath | ||
} | ||
|
||
// Equal returns true if the other diagnostic is wholly equivalent. | ||
func (d withPath) Equal(other Diagnostic) bool { | ||
o, ok := other.(withPath) | ||
|
||
if !ok { | ||
return false | ||
} | ||
|
||
if !d.Path().Equal(o.Path()) { | ||
return false | ||
} | ||
|
||
if d.Diagnostic == nil { | ||
return d.Diagnostic == o.Diagnostic | ||
} | ||
|
||
return d.Diagnostic.Equal(o.Diagnostic) | ||
} | ||
|
||
// Path returns the diagnostic path. | ||
func (d withPath) Path() *tftypes.AttributePath { | ||
return d.path | ||
} | ||
|
||
// WithPath wraps a diagnostic with path information or overwrites the path. | ||
func WithPath(path *tftypes.AttributePath, d Diagnostic) DiagnosticWithPath { | ||
wp, ok := d.(withPath) | ||
|
||
if !ok { | ||
return withPath{ | ||
Diagnostic: d, | ||
path: path, | ||
} | ||
} | ||
|
||
wp.path = path | ||
|
||
return wp | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.