Skip to content

Commit

Permalink
process: Catch conversion errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jarofgreen committed Nov 10, 2022
1 parent ec2431d commit eb77de6
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions cove_ofds/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from libcoveofds.jsonschemavalidate import JSONSchemaValidator
from libcoveofds.python_validate import PythonValidate
from libcoveofds.schema import OFDSSchema
from sentry_sdk import capture_exception

import cove_ofds.jsonschema_validation_errors
from libcoveweb2.models import SuppliedDataFile
Expand Down Expand Up @@ -252,17 +253,22 @@ def process(self, process_data: dict) -> dict:
with open(process_data["json_data_filename"]) as fp:
data = json.load(fp)

converter = JSONToGeoJSONConverter()
converter.process_package(data)
try:
converter = JSONToGeoJSONConverter()
converter.process_package(data)

with open(self.nodes_file_name, "w") as fp:
json.dump(converter.get_nodes_geojson(), fp, indent=4)
with open(self.nodes_file_name, "w") as fp:
json.dump(converter.get_nodes_geojson(), fp, indent=4)

with open(self.spans_file_name, "w") as fp:
json.dump(converter.get_spans_geojson(), fp, indent=4)
with open(self.spans_file_name, "w") as fp:
json.dump(converter.get_spans_geojson(), fp, indent=4)

with open(self.meta_file_name, "w") as fp:
json.dump(converter.get_meta_json(), fp, indent=4)
with open(self.meta_file_name, "w") as fp:
json.dump(converter.get_meta_json(), fp, indent=4)

except Exception as err:
capture_exception(err)
# TODO log and show to user. https://github.com/Open-Telecoms-Data/cove-ofds/issues/24

return process_data

Expand Down Expand Up @@ -325,12 +331,17 @@ def process(self, process_data: dict) -> dict:
"truncation_length": 9,
}

flattentool.flatten(process_data["json_data_filename"], **flatten_kwargs)
try:
flattentool.flatten(process_data["json_data_filename"], **flatten_kwargs)

# Make Zip file of all CSV files
with zipfile.ZipFile(self.csvs_zip_filename, "w") as out_zip:
for f in self._get_list_csv_filenames():
out_zip.write(os.path.join(self.output_dir, f), arcname=f)

# Make Zip file of all CSV files
with zipfile.ZipFile(self.csvs_zip_filename, "w") as out_zip:
for f in self._get_list_csv_filenames():
out_zip.write(os.path.join(self.output_dir, f), arcname=f)
except Exception as err:
capture_exception(err)
# TODO log and show to user. https://github.com/Open-Telecoms-Data/cove-ofds/issues/24

return process_data

Expand Down

0 comments on commit eb77de6

Please sign in to comment.