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