Skip to content

Commit

Permalink
🐛 Return error if no platform information (#3992)
Browse files Browse the repository at this point in the history
`SystemInfo.Get` used to return an error if it couldn't get the
platform information.
This regressed in #3660 where
nil platform info stopped returning an error
  • Loading branch information
jaym authored May 14, 2024
1 parent 2760dac commit b22ac63
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions providers-sdk/v1/sysinfo/sysinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package sysinfo

import (
"errors"

"github.com/rs/zerolog/log"

"go.mondoo.com/cnquery/v11"
Expand Down Expand Up @@ -44,13 +46,17 @@ func Get() (*SystemInfo, error) {
Type: "local",
}, &asset)

fingerprint, platform, err := id.IdentifyPlatform(conn, asset.Platform, asset.IdDetector)
if err == nil {
fingerprint, platform, _ := id.IdentifyPlatform(conn, asset.Platform, asset.IdDetector)
if fingerprint != nil {
if len(fingerprint.PlatformIDs) > 0 {
sysInfo.PlatformId = fingerprint.PlatformIDs[0]
}
}

if platform == nil {
return nil, errors.New("failed to detect the OS")
}

sysInfo.Platform = platform

sysInfo.Hostname, _ = hostname.Hostname(conn, sysInfo.Platform)
Expand Down
2 changes: 1 addition & 1 deletion providers/os/id/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func IdentifyPlatform(conn shared.Connection, p *inventory.Platform, idDetectors

// if we found zero platform ids something went wrong
if len(platformIds) == 0 {
return nil, nil, errors.New("could not determine a platform identifier")
return nil, p, errors.New("could not determine a platform identifier")
}

fingerprint.PlatformIDs = platformIds
Expand Down

0 comments on commit b22ac63

Please sign in to comment.