Fix how ErrrorData is marshaled (#2565)
## Description The error type does not get marshaled which can lead to errors when we try to un-marshal a manifest that had errors stored in it. Repro here: https://go.dev/play/p/tgj8oq5CGFd For now - this disables JSON marshaling and also fixes the error un-marshaling. I have added a regression test to verify both behaviors. As a follow-up, I believe we can implement a custom marshaler. ## Does this PR need a docs update or release note? - [ ] ✅ Yes, it's included - [ ] 🕐 Yes, but in a later PR - [x] ⛔ No ## Type of change <!--- Please check the type of change your PR introduces: ---> - [ ] 🌻 Feature - [x] 🐛 Bugfix - [ ] 🗺️ Documentation - [ ] 🤖 Test - [ ] 💻 CI/Deployment - [ ] 🧹 Tech Debt/Cleanup ## Test Plan <!-- How will this be tested prior to merging.--> - [ ] 💪 Manual - [x] ⚡ Unit test - [ ] 💚 E2E
This commit is contained in:
parent
207232e8d9
commit
c3f5e50b9f
@ -32,8 +32,8 @@ type Errors struct {
|
||||
// ErrorsData provides the errors data alone, without sync
|
||||
// controls, allowing the data to be persisted.
|
||||
type ErrorsData struct {
|
||||
Err error `json:"err"`
|
||||
Errs []error `json:"errs"`
|
||||
Err error `json:"-"`
|
||||
Errs []error `json:"-"`
|
||||
FailFast bool `json:"failFast"`
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
package fault_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@ -204,3 +206,48 @@ func (suite *FaultErrorsUnitSuite) TestData() {
|
||||
assert.ElementsMatch(t, n.Errs(), d.Errs)
|
||||
assert.True(t, d.FailFast)
|
||||
}
|
||||
|
||||
func (suite *FaultErrorsUnitSuite) TestMarshalUnmarshal() {
|
||||
t := suite.T()
|
||||
|
||||
// not fail-fast
|
||||
n := fault.New(false)
|
||||
require.NotNil(t, n)
|
||||
|
||||
n.Add(errors.New("1"))
|
||||
n.Add(errors.New("2"))
|
||||
|
||||
data := n.Data()
|
||||
|
||||
jsonStr, err := json.Marshal(data)
|
||||
require.NoError(t, err)
|
||||
|
||||
um := fault.ErrorsData{}
|
||||
|
||||
err = json.Unmarshal(jsonStr, &um)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
type legacyErrorsData struct {
|
||||
Err error `json:"err"`
|
||||
Errs []error `json:"errs"`
|
||||
FailFast bool `json:"failFast"`
|
||||
}
|
||||
|
||||
func (suite *FaultErrorsUnitSuite) TestUnmarshalLegacy() {
|
||||
t := suite.T()
|
||||
|
||||
oldData := &legacyErrorsData{
|
||||
Errs: []error{fmt.Errorf("foo error"), fmt.Errorf("foo error"), fmt.Errorf("foo error")},
|
||||
}
|
||||
|
||||
jsonStr, err := json.Marshal(oldData)
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Logf("jsonStr is %s\n", jsonStr)
|
||||
|
||||
um := fault.ErrorsData{}
|
||||
|
||||
err = json.Unmarshal(jsonStr, &um)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user