Skip to content

Commit

Permalink
Fix exception handling and propagation in failure situations
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Apr 23, 2024
1 parent 37cb0cb commit 91d4a0f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
In this mode, the Grafana URL can optionally be defined using the
environment variable `GRAFANA_URL`.
* Fix exit codes in failure situations.
* Fix exception handling and propagation in failure situations.

## 0.2.0 (2022-02-05)
* Migrated from grafana_api to grafana_client
Expand Down
10 changes: 7 additions & 3 deletions grafana_import/grafana.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,15 +321,19 @@ def import_dashboard(self, dashboard):
new_dash['dashboard']['uid'] = None
new_dash['dashboard']['id'] = None
else:
raise GrafanaApi.GrafanaBadInputError("dashboard already exists in an another folder and allow_new is False.")
raise GrafanaClient.GrafanaBadInputError(
"Dashboard with the same title already exists in another folder. "
"Use `allow_new` to permit creation in a different folder.")
#** case d) send a copy to existing dash : update existing
elif new_dash['folderId'] == old_dash['folderId']:
if new_dash['dashboard']['uid'] != old_dash['uid']:
if 'uid' not in new_dash['dashboard'] or new_dash['dashboard']['uid'] != old_dash['uid']:
if self.overwrite:
new_dash['dashboard']['uid'] = old_dash['uid']
new_dash['dashboard']['id'] = old_dash['id']
else:
raise GrafanaApi.GrafanaBadInputError("dashboard already exists in this folder with an another id and overwrite is False.")
raise GrafanaClient.GrafanaBadInputError(
"Dashboard with the same title already exists in this folder with another uid. "
"Use `overwrite` to permit overwriting it.")
else:
#force the creation of a new dashboard
new_dash['dashboard']['uid'] = None
Expand Down

0 comments on commit 91d4a0f

Please sign in to comment.