AdrianGaudebert/socorro — comment on commit 2bf93ef430d4110243060c90dfccd0b124dad968
File: socorro/external/elasticsearch/search.py line 71
By peterbe:

Using the base exception "Exception" is the same thing as just doing ``except:``

Also I think this code is wrong.

Using a blank exception is generally a bad idea. What if it raises an error because "json" has become something else and not the JSON parsing module. I.e.

```python
json = '{"foo": 123}' # oops overriding imported module name
...
try:
es_data = json.loads(es_result[0])
except:
logger.debug("Here's what it failed to parse: %s", ...)
raise
```

Another thing that could go wrong is that ``es_result[0]`` could raise an IndexError which again has nothing to do with parsing the JSON string.

Long story short, here's how I would re-write it:

```python
try:
es_data = json.loads(es_result[0])
except ValueError:
logger.debug("ElasticSearch returned something wrong: %s",
es_result[0])

raise
```