Fix panic on empty sbom (#917)

* Implement fmt.Stringer with format.ID

Signed-off-by: Dan Luhring <dan+github@luhrings.com>

* Add failing test for formats processing empty SBOMs

Signed-off-by: Dan Luhring <dan+github@luhrings.com>

* Account for nil SPDX document during Syft model conversion

Signed-off-by: Dan Luhring <dan+github@luhrings.com>
This commit is contained in:
Dan Luhring
2022-03-24 10:11:51 -04:00
committed by GitHub
parent cc2c0e57a0
commit a7db43f5ec
3 changed files with 36 additions and 0 deletions
@@ -1,6 +1,7 @@
package spdxhelpers
import (
"errors"
"strconv"
"strings"
@@ -17,6 +18,10 @@ import (
)
func ToSyftModel(doc *spdx.Document2_2) (*sbom.SBOM, error) {
if doc == nil {
return nil, errors.New("cannot convert SPDX document to Syft model because document is nil")
}
spdxIDMap := make(map[string]interface{})
s := &sbom.SBOM{