Skip to content

Commit 2c3e14d

Browse files
anxdpanicsvilenmarkov
authored andcommitted
[sensors] allow sensor readings when there are warnings
1 parent 8e71afe commit 2c3e14d

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

internal/glance/cli.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func parseCliOptions() (*cliOptions, error) {
9696
func cliSensorsPrint() int {
9797
tempSensors, err := sensors.SensorsTemperatures()
9898
if err != nil {
99-
fmt.Printf("Failed to retrieve list of sensors: %v\n", err)
99+
fmt.Printf("Errors encountered while retrieving list of sensors:\n %v\n", err)
100100
if warns, ok := err.(*sensors.Warnings); ok {
101101
for _, w := range warns.List {
102102
fmt.Printf(" - %v\n", w)
@@ -106,13 +106,14 @@ func cliSensorsPrint() int {
106106
return 1
107107
}
108108

109-
if len(tempSensors) == 0 {
109+
if tempSensors == nil || len(tempSensors) == 0 {
110110
fmt.Println("No sensors found")
111111
return 0
112112
}
113113

114+
fmt.Println("Sensors found:")
114115
for _, sensor := range tempSensors {
115-
fmt.Printf("%s: %.1f°C\n", sensor.SensorKey, sensor.Temperature)
116+
fmt.Printf(" %s: %.1f°C\n", sensor.SensorKey, sensor.Temperature)
116117
}
117118

118119
return 0

pkg/sysinfo/sysinfo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ func Collect(req *SystemInfoRequest) (*SystemInfo, []error) {
205205
// also disabled on openbsd because it's not implemented by go-psutil
206206
if runtime.GOOS != "windows" && runtime.GOOS != "openbsd" {
207207
sensorReadings, err := sensors.SensorsTemperatures()
208-
if err == nil {
208+
if sensorReadings != nil && len(sensorReadings) > 0 {
209209
if req.CPUTempSensor != "" {
210210
for i := range sensorReadings {
211211
if sensorReadings[i].SensorKey == req.CPUTempSensor {

0 commit comments

Comments
 (0)