ITADN

add basic error handling

#13Pull Requestabbbi 创建于 2024-01-15
A
abbbicommented
hi, pull request includes: 1) code formatting using python black code formatter 2) adds basic error handling if snapshot creation fails: changes the exit code of the script based on how many errors during snapshot creation happen, this makes it easier for callers to report errors during operation based on exit code. Example of successful run: ``` (venv) abi@cefix ~/hcloud-snapshot-as-backup (error)$ python3 snapshot-as-backup.py Snapshot #144915461 (Server #13281368) has been created Snapshot #144915462 (Server #28223848) has been created Snapshot #144915463 (Server #28283699) has been created Snapshot #144915464 (Server #41647785) has been created Snapshot #144915465 (Server #41664956) has been created Snapshot #144915334 (Server #13281368) was successfully deleted Snapshot #144915335 (Server #28223848) was successfully deleted Snapshot #144915336 (Server #28283699) was successfully deleted Snapshot #144915337 (Server #41647785) was successfully deleted Snapshot #144915338 (Server #41664956) was successfully deleted (venv) abi@cefix ~/hcloud-snapshot-as-backup (error)$ echo $? 0 ``` Example of errnous run: ``` (venv) abi@cefix ~/hcloud-snapshot-as-backup (error)$ python3 snapshot-as-backup.py Snapshot for Server #13281368 could not be created: Locked { "error": { "message": "cannot perform operation because server is locked", "code": "locked", "details": null } } [..] (venv) abi@cefix ~/hcloud-snapshot-as-backup (error)$ echo $? 5 ```
合并状态:未合并 关闭于 2024-02-01 1 条评论