Safer showDiagnostics in -json-into

Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
This commit is contained in:
Christian Mesh
2025-12-17 15:39:00 -05:00
parent 48c4feed7e
commit 98ab59f92c

View File

@@ -762,12 +762,12 @@ func (m *Meta) showDiagnostics(vals ...interface{}) {
} }
if m.outputJSONInto != "" { if m.outputJSONInto != "" {
out, err := os.OpenFile(m.outputJSONInto, os.O_RDWR|os.O_CREATE, 0600) // This is a weird workaround for init and get using the legacy view wrappers mixed with the new view system
if err != nil { wrapped, ok := m.Ui.(*WrappedUi)
panic(err) if wrapped == nil || !ok {
panic("BUG: incorrect initialization of meta command structure")
} }
jsonView := views.NewJSONView(m.View, out) wrapped.jsonView.Diagnostics(diags)
jsonView.Diagnostics(diags)
return return
} }
if m.outputInJSON { if m.outputInJSON {