Skip to content

Commit 7d5cbfa

Browse files
Make some minor improvements to error handling
1 parent 29df91f commit 7d5cbfa

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

cloud_functions/stage_chunk/main.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,11 @@ def trigger_stage_chunk(event, context):
7070
message = base64.b64decode(event["data"]).decode("utf-8")
7171
data = json.loads(message)
7272

73-
bucket = data.get("bucket")
74-
name = data.get("name")
73+
try:
74+
bucket = data["bucket"]
75+
name = data["name"]
76+
except KeyError as e:
77+
raise ValueError(f"Missing expected key in Pub/Sub message: {e}")
7578

7679
if not bucket or not name:
7780
raise ValueError("Missing 'bucket' or 'name' in Pub/Sub message")

cloud_functions/stage_chunk/stage_chunk_beam_job.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
from apache_beam.io.filesystems import FileSystems
2727
import argparse
2828
import logging
29-
import sys
3029

3130

3231
class BeamSuppressUpdateDestinationSchemaWarning(logging.Filter):
@@ -159,6 +158,8 @@ def run(argv=None):
159158
input_path = custom_options.input_path
160159
triggering_frequency = custom_options.triggering_frequency
161160
priority = custom_options.priority
161+
if priority not in ["BATCH", "INTERACTIVE"]:
162+
raise ValueError(f"Invalid BigQuery priority: {priority}")
162163

163164
# Validate available input files
164165
table_names = ["DiaObject", "DiaSource", "DiaForcedSource"]

0 commit comments

Comments
 (0)