diff --git a/commcare_export/env.py b/commcare_export/env.py index 14df587..2b2a522 100644 --- a/commcare_export/env.py +++ b/commcare_export/env.py @@ -1,6 +1,8 @@ import hashlib import json +import logging import operator +import sys import uuid from typing import Any, Dict, Union, overload @@ -12,6 +14,8 @@ from jsonpath_ng import jsonpath from jsonpath_ng.parser import parse as parse_jsonpath +logger = logging.getLogger(__name__) + JSONPATH_CACHE = {} @@ -590,7 +594,23 @@ def lookup(self, key): def emit_table(self, table_spec): self.emitted = True table_spec.rows = self._unwrap_row_vals(table_spec.rows) - self.writer.write_table(table_spec) + try: + self.writer.write_table(table_spec) + except Exception as err: + if ( + not logger.isEnabledFor(logging.DEBUG) # not --verbose + and 'Row size too large' in str(err) + ): + logging.error( + 'Row size too large. The amount of data required by rows ' + 'is more than this type of database table allows. One ' + 'way to resolve this error is to reduce the number of ' + 'columns that you are exporting. A general guideline is ' + 'not to exceed 200 columns.' + ) + sys.exit(1) + else: + raise def has_emitted_tables(self): return self.emitted