Skip to content

Gufo Err Example: Global Hook

Lets install the error handling as the global python exception hook.

global.py
from gufo.err import err

err.setup(catch_all=True)


def fail():
    msg = "failing"
    raise RuntimeError(msg)


fail()

The code is straightforward:

global.py
from gufo.err import err

err.setup(catch_all=True)


def fail():
    msg = "failing"
    raise RuntimeError(msg)


fail()

All error configuration is performed via err singleton, so we need to import it first.

global.py
from gufo.err import err

err.setup(catch_all=True)


def fail():
    msg = "failing"
    raise RuntimeError(msg)


fail()

err.setup() function must be called to initialize and confugure the error protection. catch_all argument set to true to replace the Python global error handling. See Err.setup() for details.

global.py
from gufo.err import err

err.setup(catch_all=True)


def fail():
    msg = "failing"
    raise RuntimeError(msg)


fail()

Lets define the function which will intentionally fail.

global.py
from gufo.err import err

err.setup(catch_all=True)


def fail():
    msg = "failing"
    raise RuntimeError(msg)


fail()

And call it.

Running

Run example as:

$ python3 examples/global.py

And got the output:

Error: 39dc9706-9550-5959-9c67-e702d036d4f9
Traceback (most resent call last):
  File "/workspaces/gufo_err/examples/global.py", line 10, in <module>
    fail()
  File "/workspaces/gufo_err/examples/global.py", line 7, in fail
    raise RuntimeError("failing")
RuntimeError: failing

Just like a default python traceback? Sure. Gufo Err installs terse traceback format by default to mimic Python's default behavior. But note the first string. 39dc9706-9550-5959-9c67-e702d036d4f9 is the error fingerprint - the unique error discriminator.

Lets run our example again and check the output:

Error: 39dc9706-9550-5959-9c67-e702d036d4f9
Traceback (most resent call last):
  File "/workspaces/gufo_err/examples/global.py", line 10, in <module>
    fail()
  File "/workspaces/gufo_err/examples/global.py", line 7, in fail
    raise RuntimeError("failing")
RuntimeError: failing

Error fingerprint is the same. Fingerprint stability is the key to the error analysis. Who want to analyze same error again and again?