osbuild: check if result objects are nil in Write()

Before dereferencing the method receiver in Write(), check if the object
is nil and return early.

Fixes #2002

Signed-off-by: Achilleas Koutsou <achilleas@koutsou.net>
This commit is contained in:
Achilleas Koutsou 2021-11-16 12:26:57 +01:00 committed by Sanne Raymaekers
parent 42d7979d65
commit 7f8a1b314a
2 changed files with 4 additions and 2 deletions

View file

@ -81,8 +81,9 @@ func (result *StageResult) UnmarshalJSON(data []byte) error {
}
func (cr *Result) Write(writer io.Writer) error {
if cr.Build == nil && len(cr.Stages) == 0 && cr.Assembler == nil {
if cr == nil || (cr.Build == nil && len(cr.Stages) == 0 && cr.Assembler == nil) {
fmt.Fprintf(writer, "The compose result is empty.\n")
return nil
}
if cr.Build != nil {

View file

@ -201,8 +201,9 @@ func (res *Result) fromV1(resv1 osbuild1.Result) {
}
func (res *Result) Write(writer io.Writer) error {
if res.Log == nil {
if res == nil || res.Log == nil {
fmt.Fprintf(writer, "The compose result is empty.\n")
return nil
}
// The pipeline results don't have a stable order