Skip to content

Commit

Permalink
add custom exception to propagate error message to harmony
Browse files Browse the repository at this point in the history
  • Loading branch information
sliu008 committed Oct 3, 2024
1 parent a40f32b commit 7e675d2
Show file tree
Hide file tree
Showing 5 changed files with 634 additions and 538 deletions.
4 changes: 3 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ confidence=
disable=too-many-lines,
too-many-arguments,
too-many-locals,
no-member
no-member,
too-many-positional-arguments,
too-many-statements

# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]
### Added
- Added custom exception to progate error messages to harmony.
### Changed
### Deprecated
### Removed
Expand Down
24 changes: 24 additions & 0 deletions podaac/subsetter/subset_harmony.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import subprocess
import shutil
from tempfile import mkdtemp
import traceback
from typing import List, Union

import pystac
Expand All @@ -31,13 +32,34 @@
import numpy as np
from harmony import BaseHarmonyAdapter
from harmony.util import download, stage, generate_output_filename, bbox_to_geometry
from harmony.exceptions import HarmonyException

from podaac.subsetter import subset
from podaac.subsetter.subset import SERVICE_NAME

DATA_DIRECTORY_ENV = "DATA_DIRECTORY"


class L2SSException(HarmonyException):
"""Base class for exceptions in the Harmony GDAL Adapter."""

def __init__(self, original_exception):
# Extract the last traceback entry (most recent call) for the error location
tb = traceback.extract_tb(original_exception.__traceback__)[-1]

# Get the error details: file, line, function, and message
filename = tb.filename
lineno = tb.lineno
funcname = tb.name
error_msg = str(original_exception)

# Format the error message to be more readable
readable_message = (f"Error in file '{filename}', line {lineno}, in function '{funcname}': "
f"{error_msg}")

super().__init__(readable_message, 'nasa/harmony-gdal-adapter')


def podaac_to_harmony_bbox(bbox: np.ndarray) -> Union[np.ndarray, float]:
"""
Convert PO.DAAC bbox ((west, east), (south, north))
Expand Down Expand Up @@ -206,6 +228,8 @@ def filter_by_subtype(variables, subtype):

# Return the STAC record
return result
except Exception as ex:
raise L2SSException(ex) from ex
finally:
# Clean up any intermediate resources
shutil.rmtree(temp_dir)
Expand Down
Loading

0 comments on commit 7e675d2

Please sign in to comment.