Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

process: Catch conversion errors #41

Merged
merged 1 commit into from
Nov 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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