canonical / canonical/operator
Provide more context when raising ModelError
- Dominant language
- Python
- Stars
- 267
- Forks
- 136
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 28
Description
Recently we received a log blob that included:
```
unit-otelcol-0: 08:53:35 ERROR unit.otelcol/0.juju-log grafana-dashboards-consumer:262: Uncaught exception while in charm code:
Traceback (most recent call last):
...
ops.hookcmds._utils.Error: command ('relation-get', '--format=json', '-r', '250', '--app', '-', 'otelcol') exited with status 1
...
ops.model.ModelError: ERROR permission denied (unauthorized access)
```
The trouble is that when we get to triage/troubleshoot, the full original logs/env are not available to us, so it is difficult to pinpoint what went wrong.
It would be helpful if a ModelError exception message included:
- hook name or action name
- (relation name and id are in the log blob above, but "far away" from the ModelError message)
Perhaps jujucontext could have a method such as "error_message_context" that would format some details. For example, if the current hook is a secret hook, then render fields relevant to secrets, etc.
Contributor guide
Research direction
Start by tracing where ModelError is raised and how jujucontext exposes the current hook or action context. Review existing exception and context tests, then define what context should be included for hooks, actions, relations, and secrets; done means errors provide useful contextual details without requiring the original log blob.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- developer-experience
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100