-
Notifications
You must be signed in to change notification settings - Fork 171
ec2_tags.py prints stacktrace when run outside of EC2 #149
Comments
@frioux, this seems good to me. What is the exception that was being raised? It is likely that there are subtle import differences between the plain python context and the salt context. |
Good programming practice suggests you should only except the exception you expect try:
m = boto.utils.get_instance_metadata(timeout=0.1, num_retries=1)
return bool(m)
except urllib2.exceptions.URLError:
return False so that the |
Ah, saw the comment was updated-- ignore this. |
@jfindlay the reason I did it the way I did was to make it clear that I am bewildered that not importing the package lets exceptions through. The more correct way makes sense for deployment. |
If you can explain it I'd love it :) |
Should I submit a PR or will one of you guys edit the original? |
@blast-hardcheese, but have you no expression on my excellent alliteration? @frioux, when you say that it lets the exception through do you mean it results in a stack trace whereas not importing the exception does not result in a stack trace? |
I was wrong. After getting some help from a friend, I found that boto is internally using boto.log.exception. I think the solution will either be to fix boto (maybe with a flag?) or to not use boto to check, like ec2_info.py does. |
The import affected the result only because that import line is incorrect and throwing an
|
@jfindlay Most definitely! // your expert elocution // commands much respect! |
note that it's now mid-2019, and this error is still present. I've just checked and @spazm's code does fix the problem, so it'd be really great to get that merged in. |
I am not really a python programmer but this is crazy to me, and my coworker who does claim to be a snake lord was confused too.
Basically, ec2_tags.py raises an exception that is uncatchable unless you import
urllib2.exceptions.URLError
. The even weirder thing is that the exception is catchable when the code is run directly from python; only when run via salt does this issue manifest itself.This patch (not a PR because I'm not confident in it enough) fixed it, but I have no idea why:
The text was updated successfully, but these errors were encountered: