Skip to content

Commit

Permalink
Improve exception logging
Browse files Browse the repository at this point in the history
  • Loading branch information
roywilly committed Jan 22, 2024
1 parent 53aac8c commit 18c8f74
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 28 deletions.
59 changes: 35 additions & 24 deletions src/fmu/sumo/uploader/_sumofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# pylint: disable=C0103 # allow non-snake case variable names

logger = logging.getLogger(__name__)
logger.setLevel(logging.CRITICAL)
logger.setLevel(logging.WARNING)


def _get_segyimport_cmdstr(blob_url, object_id, file_path, sample_unit):
Expand Down Expand Up @@ -136,10 +136,8 @@ def upload_to_sumo(self, sumo_parent_id, sumo_connection):
)
pass
except (httpx.TimeoutException, httpx.ConnectError) as err:
logger.warning(
"Metadata upload timeout or connection exception",
err,
type(err),
logger.warn(
f"Metadata upload timeout/connection exception {err} {type(err)}"
)
result.update(
{
Expand All @@ -150,8 +148,8 @@ def upload_to_sumo(self, sumo_parent_id, sumo_connection):
)
pass
except httpx.HTTPStatusError as err:
logger.warning(
"Metadata upload statuserror exception", err, type(err)
logger.warn(
f"Metadata upload statuserror exception {err} {type(err)}"
)
result.update(
{
Expand All @@ -162,18 +160,18 @@ def upload_to_sumo(self, sumo_parent_id, sumo_connection):
)
pass
except Exception as err:
logger.warning("Metadata upload exception", err, type(err))
logger.warn(f"Metadata upload exception {err} {type(err)}")
result.update(
{
"status": "failed",
"metadata_upload_response_status_code": err.response.status_code,
"metadata_upload_response_text": err.response.reason_phrase,
"metadata_upload_response_status_code": 500,
"metadata_upload_response_text": str(err),
}
)
pass

if result["metadata_upload_response_status_code"] not in [200, 201]:
logger.warning(
logger.info(
"Metadata upload unsuccessful, returning",
result["metadata_upload_response_status_code"],
)
Expand Down Expand Up @@ -221,26 +219,26 @@ def upload_to_sumo(self, sumo_parent_id, sumo_connection):
)
else:
# Outer code expects and interprets http error codes
logger.warning(
logger.warn(
"Seismic upload failed with returncode",
cmd_result.returncode,
)
upload_response.update(
{
"status_code": 418,
"text": "FAILED SEGY upload as OpenVDS. "
"text": "FAILED SEGY upload as OpenVDS command "
+ cmd_result.stderr,
}
)
pass
pass
except Exception as err:
logger.warning("Seismic upload exception", err, type(err))
logger.warn(f"Seismic upload exception {err} {type(err)}")
upload_response.update(
{
"status_code": 418,
"text": "FAILED SEGY upload as OpenVDS. "
+ str(err),
"text": "FAILED SEGY upload as OpenVDS "
+ str(err) + " " + str(type(err)),
}
)
else: # non-seismic blob
Expand All @@ -258,30 +256,43 @@ def upload_to_sumo(self, sumo_parent_id, sumo_connection):
)
pass
except (httpx.TimeoutException, httpx.ConnectError) as err:
logger.warning(
"Blob upload failed on timeout or connect", err, type(err)
logger.warn(
f"Blob upload failed on timeout/connect {err} {type(err)}"
)
upload_response.update(
{
"status": "failed",
"status_code": 500,
"text": str(err),
"blob_upload_response_status_code": 500,
"blob_upload_response_text": str(err),
}
)
pass
except httpx.HTTPStatusError as err:
logger.warning("Blob upload failed on status", err, type(err))
logger.warn(f"Blob upload failed on status {err} {type(err)}")
upload_response.update(
{
"status": "failed",
"status_code": 500,
"text": str(err),
"blob_upload_response_status_code": err.response.status_code,
"blob_upload_response_text": err.response.reason_phrase,
}
)
pass
except Exception as err:
logger.warning(
"Blob upload failed on exception", err, type(err)
logger.warn(
f"Blob upload failed on exception {err} {type(err)}"
)
upload_response.update(
{
"status": "failed",
"status_code": 500,
"text": str(err),
"blob_upload_response_status_code": 500,
"blob_upload_response_text": str(err),
}
)

_t1_blob = time.perf_counter()
Expand All @@ -301,9 +312,9 @@ def upload_to_sumo(self, sumo_parent_id, sumo_connection):
if "status_code" not in upload_response or upload_response[
"status_code"
] not in [200, 201]:
logger.warning(
"Deleting metadata since data-upload failed on object uuid",
self.sumo_object_id,
logger.warn(
"Deleting metadata since data-upload failed on object uuid "
+ self.sumo_object_id
)
result["status"] = "failed"
self._delete_metadata(sumo_connection, self.sumo_object_id)
Expand Down
7 changes: 3 additions & 4 deletions src/fmu/sumo/uploader/scripts/sumo_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from fmu.sumo import uploader

logger = logging.getLogger(__name__)
logger.setLevel(logging.CRITICAL)
logger.setLevel(logging.WARNING)

# This documentation is for sumo_uploader as an ERT workflow
DESCRIPTION = """SUMO_UPLOAD will upload files to Sumo. The typical use case is as add-on to
Expand Down Expand Up @@ -127,9 +127,8 @@ def sumo_upload_main(
)
_sumo_logger.propagate = False
_sumo_logger.warning(
"Problem related to Sumo upload for case: %s; %s",
case_metadata_path,
err,
"Problem related to Sumo upload for case: %s; %s %s",
case_metadata_path, err, type(err)
)
return

Expand Down

0 comments on commit 18c8f74

Please sign in to comment.