From ee752b0ab8f62ed298642f11bad3d3217ace54b7 Mon Sep 17 00:00:00 2001 From: Lars Karlitski Date: Wed, 25 Mar 2020 09:29:10 +0100 Subject: [PATCH] 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). --- cmd/osbuild-pipeline/main.go | 4 ++-- cmd/osbuild-worker/main.go | 4 ++-- internal/blueprint/blueprint.go | 4 ++-- internal/store/store.go | 1 - 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/cmd/osbuild-pipeline/main.go b/cmd/osbuild-pipeline/main.go index 66930097b..89c60a734 100644 --- a/cmd/osbuild-pipeline/main.go +++ b/cmd/osbuild-pipeline/main.go @@ -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) diff --git a/cmd/osbuild-worker/main.go b/cmd/osbuild-worker/main.go index b3725fa72..fa14dbff5 100644 --- a/cmd/osbuild-worker/main.go +++ b/cmd/osbuild-worker/main.go @@ -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) diff --git a/internal/blueprint/blueprint.go b/internal/blueprint/blueprint.go index cd4e922c7..018e06ed6 100644 --- a/internal/blueprint/blueprint.go +++ b/internal/blueprint/blueprint.go @@ -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 } diff --git a/internal/store/store.go b/internal/store/store.go index 950b330f3..d08108b7f 100644 --- a/internal/store/store.go +++ b/internal/store/store.go @@ -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) }