Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

ValueError exceptions in hooks are not properly handled #43

Closed
fgblomqvist opened this issue Mar 20, 2018 · 2 comments · Fixed by #45
Closed

ValueError exceptions in hooks are not properly handled #43

fgblomqvist opened this issue Mar 20, 2018 · 2 comments · Fixed by #45
Assignees

Comments

@fgblomqvist
Copy link

fgblomqvist commented Mar 20, 2018

This was discussed in #32.

I got an exception in my before_all hook that just lead to this output:

info: Configuration './dredd.yml' found, ignoring other arguments.
info: Starting backend server process with command: app run
info: Waiting 3 seconds for backend server process to start
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 317-228-483
info: Beginning Dredd testing...
info: Found Hookfiles: 0=/my/dir/hooks.py
info: Spawning 'python' hooks handler process.
info: Hooks handler stdout: Starting Dredd Python hooks handler

warn: Error connecting to the hooks handler process. Is the handler running? Retrying.
info: Successfully connected to hooks handler. Waiting 0.1s to start testing.
warn: Hook handling timed out.
warn: Hook handling timed out.
warn: Hook handling timed out.
fail: GET (200) / duration: 5004ms
warn: Hook handling timed out.

I figured out the line that was causing it and caught the exception myself:

    try:
        // code that throw exception
    except Exception as e:
        print(e)

and got this:

info: Configuration './dredd.yml' found, ignoring other arguments.
info: Starting backend server process with command: app run
info: Waiting 3 seconds for backend server process to start
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 317-228-483
info: Beginning Dredd testing...
info: Found Hookfiles: 0=/my/dir/hooks.py
info: Spawning 'python' hooks handler process.
info: Hooks handler stdout: Starting Dredd Python hooks handler

warn: Error connecting to the hooks handler process. Is the handler running? Retrying.
info: Successfully connected to hooks handler. Waiting 0.1s to start testing.
info: Hooks handler stdout: Can't reset a sequence on decendant factory <class 'tests.fixtures.factories.student.StudentFactory'>; reset sequence on <class 'tests.fixtures.factories.user.UserFactory'> or use `force=True`.

127.0.0.1 - - [20/Mar/2018 11:41:46] "GET / HTTP/1.1" 200 -
pass: GET (200) / duration: 123ms

Naturally, since I caught the exception, dredd continues to run.
But yeah, I would expect dredd_hooks to catch it for me (and stop running)?

@w-vi
Copy link
Contributor

w-vi commented Mar 26, 2018

Thanks for pointing this out, would you have an example code which caused it? My test didn't fail so I am not sure what exactly is happening.

@w-vi w-vi self-assigned this Mar 28, 2018
@fgblomqvist
Copy link
Author

fgblomqvist commented Mar 28, 2018

Just figured out more precisely what is wrong:
https://github.com/apiaryio/dredd-hooks-python/blob/master/dredd_hooks/dredd.py#L112-113

If a ValueError is raised inside a hook (which was the case above) no traceback is printed (and the exception is not passed on). Not sure why ValueErrors are treated differently, doesn't seem right. I was able to replicate it myself by simply doing this:

@hooks.before_all
def before_all(trans):
    raise ValueError()

It resulted in the same faulty behavior as above. If I instead raise an Exception, dredd_hooks prints some stuff that gets sent to dredd and is then showed to me.

@fgblomqvist fgblomqvist changed the title Exceptions in hooks are still not handled properly ValueError exceptions in hooks are not properly handled Mar 28, 2018
w-vi pushed a commit that referenced this issue Mar 29, 2018
Fixes #43

Unfortunatelly it is hard to propagate exceptions from hook files without
propagating hook handler exceptions too. This attempt tries to propagate
everything but json decoding errors which are manifestation of either the
connection being closed or some internal error. If anybody knows a better
solution I am happy to hear about it.
@w-vi w-vi closed this as completed in #45 Apr 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants