Skip to content

Commit

Permalink
Add logging for LocalProtocolError for easy debuggability in the futu…
Browse files Browse the repository at this point in the history
…re (#424)

* Add logging for LocalProtocolError for easy debuggability in the future

* Minor improvement to log message

---------

Co-authored-by: Nithin Bodanapu <nithin.bodanapu@cognite.com>
  • Loading branch information
nithinb and Nithin Bodanapu authored Jan 23, 2025
1 parent 5663a39 commit d5efbcd
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cognite/extractorutils/uploader/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
)
from urllib.parse import ParseResult, urlparse

from h11._util import LocalProtocolError
from httpx import URL, Client, Headers, Request, StreamConsumed, SyncByteStream
from requests.utils import super_len

Expand Down Expand Up @@ -481,6 +482,19 @@ def wrapped_upload(
try:
upload_file(read_file, file_meta)

except LocalProtocolError as e:
error_message = str(e)
if (
"Too much data for declared Content" in error_message
or "Too little data for declared Content-Length" in error_message
):
self.logger.error(
f"Content Length Mismatch while uploading file: {file_meta} error message: {error_message}"
)

self.add_entry_failure_logger(file_name=str(file_meta.name), error=e)
self.errors.append(e)

except Exception as e:
self.logger.exception(
f"Unexpected error while uploading file: {file_meta.external_id} {file_meta.name}"
Expand Down

0 comments on commit d5efbcd

Please sign in to comment.