Skip to content

Commit

Permalink
handle zero-byte json as not found error
Browse files Browse the repository at this point in the history
  • Loading branch information
John Readey authored and John Readey committed Dec 3, 2024
1 parent 031182c commit bb53649
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion hsds/util/storUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import numcodecs as codecs
import bitshuffle
from json import JSONDecodeError
from aiohttp.web_exceptions import HTTPInternalServerError
from aiohttp.web_exceptions import HTTPInternalServerError, HTTPNotFound

from .. import hsds_logger as log
from .s3Client import S3Client
Expand Down Expand Up @@ -425,6 +425,13 @@ async def getStorJSONObj(app, key, bucket=None):

data = await client.get_object(key, bucket=bucket)

if len(data) == 0:
# treat a zero-byte file as not found for JSON
# seems with posix drivers we can sometimes get a file result
# before any data gets written to it
log.warn(f"zero bytes returned for key: {key} bucket:{bucket}")
raise HTTPNotFound()

try:
json_dict = json.loads(data.decode("utf8"))
except UnicodeDecodeError:
Expand Down

0 comments on commit bb53649

Please sign in to comment.