impactlab / eemeter

‼️ MOVED TO https://github.com/openeemeter/eemeter - Core computation engine for the Open Energy Efficiency Meter
https://eemeter.readthedocs.io/
MIT License
25 stars 13 forks source link

Handle corrupted json data files in weather cache #124

Closed philngo closed 8 years ago

philngo commented 8 years ago

For instance, I got the following error decoding corrupted json:

../../.virtualenvs/oeem-energy-datastore/lib/python3.4/site-packages/eemeter/examples.py:21: in get_example_project
    weather_source = GSODWeatherSource(station,2011,2015)
../../.virtualenvs/oeem-energy-datastore/lib/python3.4/site-packages/eemeter/weather.py:545: in __init__
    cache_filename)
../../.virtualenvs/oeem-energy-datastore/lib/python3.4/site-packages/eemeter/weather.py:497: in __init__
    self.load_from_cache()
../../.virtualenvs/oeem-energy-datastore/lib/python3.4/site-packages/eemeter/weather.py:521: in load_from_cache
    data = json.load(f)
/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/lib/python3.4/json/__init__.py:268: in load
    parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/lib/python3.4/json/__init__.py:318: in loads
    return _default_decoder.decode(s)
/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/lib/python3.4/json/decoder.py:343: in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <json.decoder.JSONDecoder object at 0x104ed0588>, s = '', idx = 0

    def raw_decode(self, s, idx=0):
        """Decode a JSON document from ``s`` (a ``str`` beginning with
            a JSON document) and return a 2-tuple of the Python
            representation and the index in ``s`` where the document ended.

            This can be used to decode a JSON document from a string that may
            have extraneous data at the end.

            """
        try:
            obj, end = self.scan_once(s, idx)
        except StopIteration as err:
>           raise ValueError(errmsg("Expecting value", s, err.value)) from None
E           ValueError: Expecting value: line 1 column 1 (char 0)

I think the appropriate behavior should be to clear the cache for that station and move on, recreating it as necessary.