Search code examples
pythonbitbucket-server

Python continue script after failure


I am working with a python api for Atlassian's stash application.

The script fails to delete a project because it has repos inside and then exits.

Traceback (most recent call last):
  File "stash.py", line 38, in <module>
    stash.projects[p["key"]].delete()
  File "<string>", line 2, in delete
  File "/usr/local/lib/python2.7/site-packages/stashy/errors.py", line 46, in ok_or_error
    maybe_throw(response)
  File "/usr/local/lib/python2.7/site-packages/stashy/errors.py", line 40, in maybe_throw
    raise e
stashy.errors.GenericException: 409: {u'errors': [{u'message': u'The project "TEST" cannot be deleted because it has repositories.', u'exceptionName': u'com.atlassian.bitbucket.IntegrityException', u'context': None}]}

Is it possible to show the error but continue with the script?


Solution

  • It's called try .. expect pattern or exception handling in Python.

    In the simplest form:

    try:
        stash.projects[p["key"]].delete()
    except Exception as e:
        print(e)
    

    More info: