Skip to content

Commit 8143f33

Browse files
committed
feat: improve global error handling with network info and traceback
1 parent 57ac3d5 commit 8143f33

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

main.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import asyncio
2+
import logging
3+
import traceback
24

35
import dotenv
46

@@ -7,14 +9,21 @@
79
from observer.message import Message, MessageLevel
810
from observer.observer import log_message, observer_loop
911

12+
LOGGER = logging.getLogger()
13+
1014

1115
def main(config: Configuration):
1216
try:
1317
asyncio.run(observer_loop(config))
1418
except Exception as e:
15-
mb = Message.builder()
16-
message = mb.build(MessageLevel.CRITICAL, (f"Observer crashed. Reason: {e}"))
19+
mb = Message.builder().add(network=config.chain_id)
20+
message = mb.build(
21+
MessageLevel.CRITICAL,
22+
(f"observer crashed (traceback in logs) - {e}"),
23+
)
1724
log_message(config, message)
25+
LOGGER.exception(e)
26+
LOGGER.error(traceback.format_exc())
1827

1928

2029
if __name__ == "__main__":

0 commit comments

Comments
 (0)