Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Over broad exception catching (except Exception) #59

Closed
joneskoo opened this issue Dec 8, 2014 · 2 comments
Closed

Over broad exception catching (except Exception) #59

joneskoo opened this issue Dec 8, 2014 · 2 comments

Comments

@joneskoo
Copy link

joneskoo commented Dec 8, 2014

I have an issue where I'm running pyelftools and need to interrupt processing. I'm calling pyelftools from a Celery task. Celery cancels tasks by raising an celery.exceptions.Terminated exception. pyelftools unfortunately catches this and as a result, my task does not get cancelled.

As a fix, all occurences of except Exception should be changed to catch more specific exceptions, such as IOError, ValueError etc.

I did not track which of the exceptions I'm hitting yet, but here's one example of offending try-except: https://github.com/eliben/pyelftools/blob/master/elftools/construct/core.py#L352

Any chance someone familiar with the pyelftools internals could determine which exceptions actually need to be caught and make the changes? Here's a list.

$ git grep --line-number "except Exception"
elftools/construct/core.py:238:        except Exception as e:
elftools/construct/core.py:352:        except Exception as ex:
elftools/construct/core.py:357:        except Exception as ex:
elftools/construct/core.py:903:                except Exception:
elftools/construct/debug.py:113:        except Exception:
elftools/construct/debug.py:124:        except Exception:
@eliben
Copy link
Owner

eliben commented Dec 8, 2014

The problem here is that your code paths point to construct, which is a sub-library. This change would first need to be made upstream in construct.

@joneskoo
Copy link
Author

joneskoo commented Dec 8, 2014

Thanks @eliben . I'll see about reporting this to further upstream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants