mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 03:04:09 +01:00
improve logging in case of exception
This commit is contained in:
@@ -25,6 +25,12 @@ def main():
|
||||
parser.add_argument(
|
||||
"-i", "--icon", action="store_true", help="Show waste type icon"
|
||||
)
|
||||
parser.add_argument(
|
||||
"-t",
|
||||
"--traceback",
|
||||
action="store_true",
|
||||
help="Print exception information and stack trace",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
# read secrets.yaml
|
||||
@@ -97,8 +103,10 @@ def main():
|
||||
print(f" {x.date.isoformat()}: {x.type}{icon_str}")
|
||||
except KeyboardInterrupt:
|
||||
exit()
|
||||
except Exception:
|
||||
print(traceback.format_exc())
|
||||
except Exception as exc:
|
||||
print(f" {name} failed with exception: {exc}")
|
||||
if args.traceback:
|
||||
print(indent(traceback.format_exc(), 4))
|
||||
|
||||
|
||||
def replace_secret(secrets, d):
|
||||
@@ -116,5 +124,10 @@ def replace_secret(secrets, d):
|
||||
print(f"identifier '{id}' not found in {SECRET_FILENAME}")
|
||||
|
||||
|
||||
def indent(s, count):
|
||||
indent = " " * count
|
||||
return "\n".join([indent + line for line in s.split("\n")])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
@@ -218,6 +218,7 @@ The script supports the following options:
|
||||
| `-s` | SOURCE | [Source name](https://github.com/mampfes/hacs_waste_collection_schedule#source-configuration-variables) (source file name without ending `.py`) |
|
||||
| `-l` | - | List all found dates. |
|
||||
| `-i` | - | Add icon name to output. Only effective together with `-l`. |
|
||||
| `-t` | - | Show extended exception info and stack trace. |
|
||||
|
||||
For debugging purposes of a single source, it is recommended to use the `-s SOURCE` option. If used without any arguments provided, the script tests every script in the `custom_components/waste_collection_schedule/waste_collection_schedule/source` folder and prints the number of found entries for every test case.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user