Azure / azure-storage-python

Microsoft Azure Storage Library for Python
https://azure-storage.readthedocs.io
MIT License
338 stars 240 forks source link

Check length before accessing exception args #502

Closed orn688 closed 6 years ago

orn688 commented 6 years ago

If an exception without any arguments was raised during a request, an IndexError would be raised when exc.args[0] was executed under Python 3. This moves the check to make sure that exc.args is not empty so that it executes under both Python 2 and Python 3.

zezha-msft commented 6 years ago

Hi @orn688, thank you for submitting the PR!

Btw what was the exception that you encountered in Python 3 that had no argument?

orn688 commented 6 years ago

@zezha-msft I'm using Celery's soft time limits. When the soft time limit for a task is exceeded, Celery raises a SoftTimeLimitExceeded() exception with no arguments.

zezha-msft commented 6 years ago

Hi @orn688, thanks for the explanation! I'm still a bit confused, how did the exception SoftTimeLimitExceeded get thrown inside the SDK's executor?

Could you please rebase your branch on the dev branch? Thank you!!

orn688 commented 6 years ago

@zezha-msft Sure! Celery forks a worker process that uses signal.signal() to raise the exception when it receives a certain signal from another process alerting that it has exceeded its soft time limit. See: https://github.com/celery/billiard/blob/master/billiard/pool.py#L226

There has been some some discussion about changing the SoftTimeLimitExceeded exception to not inherit from Exception, which would solve the immediate issue, but it doesn't seem to have much traction and I figured that since you were checking len(exc.args) anyway for Python 2, it made sense to do it for Python 3 as well.