Raise custom exception ExporterError instead of failing with ops.model.ModelError when restart_exporter fails.
Couple of points to note:
The exporter class doesn't need a pass statement as it's not needed. This was something I learned after hitting this lint error
This does NOT resolve issue #190. The config hook still fails in that situation but it's a better error message. Will be raising another PR for the actual fix to that issue.
The new error after this patch would look something like
unit-hardware-observer-5: 12:16:57 ERROR unit.hardware-observer/5.juju-log Failed to restart the exporter.
unit-hardware-observer-5: 12:16:57 ERROR unit.hardware-observer/5.juju-log Uncaught exception while in cha
Traceback (most recent call last):
File "/var/lib/juju/agents/unit-hardware-observer-5/charm/./src/charm.py", line 344, in <module>
ops.main(HardwareObserverCharm) # type: ignore
File "/var/lib/juju/agents/unit-hardware-observer-5/charm/venv/ops/main.py", line 451, in __call__
return main(charm_class, use_juju_for_storage=use_juju_for_storage)
File "/var/lib/juju/agents/unit-hardware-observer-5/charm/venv/ops/main.py", line 436, in main
_emit_charm_event(charm, dispatcher.event_name)
File "/var/lib/juju/agents/unit-hardware-observer-5/charm/venv/ops/main.py", line 144, in _emit_charm_event
event_to_emit.emit(*args, **kwargs)
File "/var/lib/juju/agents/unit-hardware-observer-5/charm/venv/ops/framework.py", line 351, in emit
framework._emit(event)
File "/var/lib/juju/agents/unit-hardware-observer-5/charm/venv/ops/framework.py", line 853, in _emit
self._reemit(event_path)
File "/var/lib/juju/agents/unit-hardware-observer-5/charm/venv/ops/framework.py", line 942, in _reemit
custom_handler(event)
File "/var/lib/juju/agents/unit-hardware-observer-5/charm/./src/charm.py", line 224, in _on_config_changed
self._on_update_status(event)
File "/var/lib/juju/agents/unit-hardware-observer-5/charm/./src/charm.py", line 148, in _on_update_status
raise ExporterError(restart_msg)
service.ExporterError: Exporter crashed unexpectedly, please refer to systemd logs...
unit-hardware-observer-5: 12:16:58 ERROR juju.worker.uniter.operation hook "config-changed" (via hook dispatching script: dispatch) failed: exit status 1
I would also like to hear about any other ways to handle this sort of issue where BlockedStatus wouldn't work since the user can't fix the exporter crash.
Raise custom exception
ExporterError
instead of failing withops.model.ModelError
whenrestart_exporter
fails.Couple of points to note:
pass
statement as it's not needed. This was something I learned after hitting this lint errorThe new error after this patch would look something like
I would also like to hear about any other ways to handle this sort of issue where
BlockedStatus
wouldn't work since the user can't fix the exporter crash.