Skip to content

Commit 61ed24e

Browse files
[thermalctld] Print exception using repr(e) to get more information (sonic-net#103)
Allow exceptions to be printed even if they don't inherit from the `str` class
1 parent 8507085 commit 61ed24e

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

sonic-thermalctld/scripts/thermalctld

+10-8
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ try:
1414
from sonic_py_common import daemon_base, logger
1515
from sonic_py_common.task_base import ProcessTaskBase
1616
except ImportError as e:
17-
raise ImportError(str(e) + " - required module not found")
17+
raise ImportError(repr(e) + " - required module not found")
1818

1919
try:
2020
from swsscommon import swsscommon
@@ -220,7 +220,7 @@ class FanUpdater(logger.Logger):
220220
try:
221221
self._refresh_fan_status(drawer, fan, fan_index)
222222
except Exception as e:
223-
self.log_warning('Failed to update FAN status - {}'.format(e))
223+
self.log_warning('Failed to update FAN status - {}'.format(repr(e)))
224224
fan_index += 1
225225

226226
for psu_index, psu in enumerate(self.chassis.get_all_psus()):
@@ -229,7 +229,7 @@ class FanUpdater(logger.Logger):
229229
try:
230230
self._refresh_fan_status(None, fan, fan_index, '{} FAN'.format(psu_name), True)
231231
except Exception as e:
232-
self.log_warning('Failed to update PSU FAN status - {}'.format(e))
232+
self.log_warning('Failed to update PSU FAN status - {}'.format(repr(e)))
233233

234234
self._update_led_color()
235235

@@ -357,7 +357,7 @@ class FanUpdater(logger.Logger):
357357
('led_status', str(try_get(fan_status.fan.get_status_led)))
358358
])
359359
except Exception as e:
360-
self.log_warning('Failed to get led status for fan')
360+
self.log_warning('Failed to get led status for fan - {}'.format(repr(e)))
361361
fvs = swsscommon.FieldValuePairs([
362362
('led_status', NOT_AVAILABLE)
363363
])
@@ -494,7 +494,7 @@ class TemperatureUpdater(logger.Logger):
494494
try:
495495
self._refresh_temperature_status(thermal, index)
496496
except Exception as e:
497-
self.log_warning('Failed to update thermal status - {}'.format(e))
497+
self.log_warning('Failed to update thermal status - {}'.format(repr(e)))
498498

499499
self.log_debug("End temperature updating")
500500

@@ -664,8 +664,10 @@ class ThermalControlDaemon(daemon_base.DaemonBase):
664664
thermal_manager.initialize()
665665
thermal_manager.load(ThermalControlDaemon.POLICY_FILE)
666666
thermal_manager.init_thermal_algorithm(chassis)
667+
except NotImplementedError:
668+
self.log_warning('Thermal manager is not supported on this platform.')
667669
except Exception as e:
668-
self.log_error('Caught exception while initializing thermal manager - {}'.format(e))
670+
self.log_error('Caught exception while initializing thermal manager - {}'.format(repr(e)))
669671

670672
wait_time = ThermalControlDaemon.INTERVAL
671673
while not self.stop_event.wait(wait_time):
@@ -674,7 +676,7 @@ class ThermalControlDaemon(daemon_base.DaemonBase):
674676
if thermal_manager:
675677
thermal_manager.run_policy(chassis)
676678
except Exception as e:
677-
self.log_error('Caught exception while running thermal policy - {}'.format(e))
679+
self.log_error('Caught exception while running thermal policy - {}'.format(repr(e)))
678680
elapsed = time.time() - begin
679681
if elapsed < ThermalControlDaemon.INTERVAL:
680682
wait_time = ThermalControlDaemon.INTERVAL - elapsed
@@ -689,7 +691,7 @@ class ThermalControlDaemon(daemon_base.DaemonBase):
689691
if thermal_manager:
690692
thermal_manager.deinitialize()
691693
except Exception as e:
692-
self.log_error('Caught exception while destroy thermal manager - {}'.format(e))
694+
self.log_error('Caught exception while destroy thermal manager - {}'.format(repr(e)))
693695

694696
thermal_monitor.task_stop()
695697

0 commit comments

Comments
 (0)