tree-wide: panic when json marshalling fails

According to the new guidelines in docs/errors.md.

Note that this does not include code that marshals to a writer that
might fail (when a connection drops, for example).
This commit is contained in:
Lars Karlitski 2020-03-25 09:29:10 +01:00
parent ad1a12f7aa
commit ee752b0ab8
4 changed files with 6 additions and 7 deletions

View file

@ -141,7 +141,7 @@ func main() {
}
bytes, err = json.Marshal(rpmMDInfo)
if err != nil {
panic("could not marshal rpmmd struct into JSON")
panic(err)
}
} else {
manifest, err := imageType.Manifest(blueprint.Customizations, repos[arch.Name()], packageSpecs, buildPackageSpecs, imageType.Size(0))
@ -151,7 +151,7 @@ func main() {
bytes, err = json.Marshal(manifest)
if err != nil {
panic("could not marshal manifest into JSON")
panic(err)
}
}
os.Stdout.Write(bytes)

View file

@ -102,7 +102,7 @@ func (c *ComposerClient) AddJob() (*jobqueue.Job, error) {
var b bytes.Buffer
err := json.NewEncoder(&b).Encode(request{})
if err != nil {
return nil, err
panic(err)
}
response, err := c.client.Post(c.createURL("/job-queue/v1/jobs"), "application/json", &b)
if err != nil {
@ -129,7 +129,7 @@ func (c *ComposerClient) UpdateJob(job *jobqueue.Job, status common.ImageBuildSt
var b bytes.Buffer
err := json.NewEncoder(&b).Encode(&jobqueue.JobStatus{status, result})
if err != nil {
return err
panic(err)
}
urlPath := fmt.Sprintf("/job-queue/v1/jobs/%s/builds/%d", job.ID.String(), job.ImageBuildID)
url := c.createURL(urlPath)

View file

@ -43,13 +43,13 @@ type Group struct {
func (b *Blueprint) DeepCopy() (Blueprint, error) {
bpJSON, err := json.Marshal(b)
if err != nil {
return Blueprint{}, err
panic(err)
}
var bp Blueprint
err = json.Unmarshal(bpJSON, &bp)
if err != nil {
return Blueprint{}, err
panic(err)
}
return bp, nil
}

View file

@ -287,7 +287,6 @@ func (s *Store) change(f func() error) error {
if s.stateChannel != nil {
serialized, err := json.Marshal(s)
if err != nil {
// we ought to know all types that go into the store
panic(err)
}