Skip to content

Commit

Permalink
improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
kelle committed Jul 23, 2024
1 parent ccd9140 commit 2f1d7ed
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
6 changes: 4 additions & 2 deletions documentation/SpectralTypes.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Columns marked with an asterisk (*) may not be empty.
| spectral_type_string | Spectral type string | | String(20) | |
| *spectral_type_code | Numeric code corresponding to spectral type | | Float | primary |
| spectral_type_error | Uncertainty of spectral type | | Float | |
| regime | Regime for spectral type value | | | primary and foreign:Regimes.regime |
| *regime | Regime for spectral type value | | | primary and foreign:Regimes.regime |
| adopted | Flag indicating if this is the adopted measurement | | Boolean | |
| photometric | Flag indicating if this is a photometric spectral type | | Boolean | |
| comments | Free form comments | | String(1000) | |
Expand All @@ -21,4 +21,6 @@ Spectral Type Codes:
- 69 = M9
- 70 = L0
- 80 = T0
- 90 = Y0
- 90 = Y0

Regime is required however, regime = "unkwown" can be used when the regime is unknown.
25 changes: 16 additions & 9 deletions simple/utils/spectral_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,11 @@ def ingest_spectral_type(
)
if check == 1:
msg = f"Spectral type for {db_name} already in the database"
raise AstroDBError(msg)
if raise_error:
logger.error(msg)
raise AstroDBError(msg)
else:
logger.warning(msg)

logger.debug(f"Trying to insert {spt_data} into Spectral Types table ")

Expand Down Expand Up @@ -181,17 +185,20 @@ def ingest_spectral_type(
== 0
):
msg = f"The publication does not exist in the database: {reference}"
msg1 = "Add it with ingest_publication function."
msg1 = "Add it with astrodb_utils.ingest_publication function."
logger.debug(msg + msg1)
raise AstroDBError(msg)
elif "NOT NULL constraint failed: SpectralTypes.regime" in str(e):
msg = f"The regime was not provided for {source}"
logger.error(msg)
raise AstroDBError(msg)
if raise_error:
logger.error(msg)
raise AstroDBError(msg + msg1)
else:
logger.warning(msg)
else:
msg = f"Spectral type ingest failed with error {e}\n"
logger.error(msg)
raise AstroDBError(msg)
if raise_error:
logger.error(msg)
raise AstroDBError(msg)
else:
logger.warning(msg)


def convert_spt_string_to_code(spectral_type_string):
Expand Down

0 comments on commit 2f1d7ed

Please sign in to comment.