Skip to content

Commit 1788cfa

Browse files
committed
Add PublicExtraInfo interface to more selectively output the extra field
1 parent 4fcdf70 commit 1788cfa

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

internal/command/views/json/diagnostic.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,18 @@ func NewDiagnostic(diag tfdiags.Diagnostic, sources map[string][]byte) *Diagnost
144144
}
145145

146146
desc := diag.Description()
147+
extra := diag.ExtraInfo()
148+
var publicExtra tfdiags.PublicExtraInfo
149+
if e, ok := extra.(tfdiags.PublicExtraInfo); ok {
150+
publicExtra = e
151+
}
147152

148153
diagnostic := &Diagnostic{
149154
Severity: sev,
150155
Summary: desc.Summary,
151156
Detail: desc.Detail,
152157
Address: desc.Address,
153-
Extra: diag.ExtraInfo(),
158+
Extra: publicExtra,
154159
}
155160

156161
sourceRefs := diag.Source()

internal/configs/module_deprecations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ type ModuleDeprecationDiagnosticExtra struct {
3232
Deprecations []*ModuleDeprecationDiagnosticExtraDeprecationItem `json:"deprecations"`
3333
}
3434

35+
func (m *ModuleDeprecationDiagnosticExtra) IsPublic() {}
36+
3537
type ModuleDeprecationDiagnosticExtraDeprecationItem struct {
3638
Version string `json:"version"`
3739
SourceName string `json:"source_name"`

internal/tfdiags/diagnostic.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,8 @@ type FromExpr struct {
6565
Expression hcl.Expression
6666
EvalContext *hcl.EvalContext
6767
}
68+
69+
// PublicExtraInfo is an interface for marking Extra field that contain public extra information
70+
type PublicExtraInfo interface {
71+
IsPublic()
72+
}

0 commit comments

Comments
 (0)