Skip to content

Commit 76e2dac

Browse files
committed
editing error handling
1 parent 13cb6c1 commit 76e2dac

File tree

2 files changed

+8
-17
lines changed

2 files changed

+8
-17
lines changed

comp/metadata/hosthardware/impl/hosthardware.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,19 +111,22 @@ func NewHardwareHostProvider(deps Requires) Provides {
111111
}
112112
}
113113

114-
func (hh *hostHardware) fillData() {
114+
func (hh *hostHardware) fillData() error {
115115
hardwareInfo, err := hardware.Collect()
116116
if err != nil {
117117
hh.log.Errorf("Failed to collect hardware information: %v", err)
118118
hh.data = &hostHardwareMetadata{}
119-
return
119+
return err
120120
}
121+
121122
hh.data.Manufacturer = hardwareInfo.Manufacturer
122123
hh.data.ModelNumber = hardwareInfo.ModelNumber
123124
hh.data.SerialNumber = hardwareInfo.SerialNumber
124125
hh.data.Name = hardwareInfo.Name
125126
hh.data.ChassisType = hardwareInfo.ChassisType
126127
hh.data.Identifier = hardwareInfo.Identifier
128+
129+
return nil
127130
}
128131

129132
func (hh *hostHardware) writePayloadAsJSON(w http.ResponseWriter, _ *http.Request) {
@@ -137,9 +140,9 @@ func (hh *hostHardware) writePayloadAsJSON(w http.ResponseWriter, _ *http.Reques
137140
}
138141

139142
func (hh *hostHardware) getPayload() marshaler.JSONMarshaler {
140-
141-
hh.fillData()
142-
if hh.data == nil {
143+
// Try to collect hardware data
144+
if err := hh.fillData(); err != nil {
145+
hh.log.Debugf("Skipping hardware metadata payload due to collection failure: %v", err)
143146
return nil
144147
}
145148

comp/metadata/hosthardware/impl/hosthardware_test.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ func TestNewHardwareHostProvider_FullMode(t *testing.T) {
6767

6868
// Should be disabled for full mode
6969
assert.False(t, hh.InventoryPayload.Enabled, "Should be disabled in full mode")
70-
assert.Nil(t, hh.MetadataProvider, "Provider should be nil when disabled")
7170
}
7271

7372
func TestNewHardwareHostProvider_BasicMode(t *testing.T) {
@@ -109,17 +108,6 @@ func TestGetPayload(t *testing.T) {
109108
assert.NotNil(t, p.Metadata, "Host hardware metadata should not be nil")
110109
}
111110

112-
func TestGetPayload_NilData(t *testing.T) {
113-
hh := getTestHostHardware(t, nil)
114-
115-
// Set data to nil
116-
hh.data = nil
117-
118-
// Get payload should return nil when data is nil
119-
payload := hh.getPayload()
120-
assert.Nil(t, payload, "Payload should be nil when data is nil")
121-
}
122-
123111
func TestPayloadMarshalJSON(t *testing.T) {
124112
payload := &Payload{
125113
Hostname: "test-host",

0 commit comments

Comments
 (0)