Skip to content

Commit

Permalink
Additional error handlings for execution binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
thombashi committed Jul 15, 2018
1 parent 71213b5 commit f599786
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
25 changes: 16 additions & 9 deletions sqlitebiter/_ipynb_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,34 @@ def is_ipynb_url(url):
return result.scheme != "" and is_ipynb_file_path(result.path)


def _schema_not_found_error_handler(e):
if re.search("No such file or directory: .+schema.json", six.text_type(e)):
raise RuntimeError(
"ipynb file format conversion not supported for the binary version. "
"please try to install sqlitebiter via pip."
)


def load_ipynb_file(file_path, encoding):
with io.open(file_path, encoding=encoding) as f:
try:
return nbformat.read(f, as_version=4)
except AttributeError as e:
raise nbformat.reader.NotJSONError(msgfy.to_error_message(e))
except IOError as e:
if re.search("No such file or directory: .+schema.json", six.text_type(e)):
raise nbformat.reader.NotJSONError(
"ipynb file format conversion not supported for the binary version."
"please try to install sqlitebiter via pip."
)
else:
raise
except FileNotFoundError as e:
_schema_not_found_error_handler(e)
raise


def load_ipynb_url(url, proxies):
response = requests.get(url, proxies=proxies)
response.raise_for_status()

return (nbformat.reads(response.text, as_version=4), len(response.content))
try:
return (nbformat.reads(response.text, as_version=4), len(response.content))
except FileNotFoundError as e:
_schema_not_found_error_handler(e)
raise


class NbAttr(object):
Expand Down
2 changes: 1 addition & 1 deletion sqlitebiter/subcommand/_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def convert(self, file_path):
nb=load_ipynb_file(file_path, encoding=self._encoding),
source_info=source_info_record_base,
)
except nbformat.reader.NotJSONError as e:
except (nbformat.reader.NotJSONError, RuntimeError) as e:
logger.error(e)
return

Expand Down
7 changes: 6 additions & 1 deletion sqlitebiter/subcommand/_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ def convert(self, url):
source_info_record_base.source_id = self._fetch_next_source_id()

if self._format_name in IPYNB_FORMAT_NAME_LIST or is_ipynb_url(url):
nb, nb_size = load_ipynb_url(url, proxies=self.__get_proxies())
try:
nb, nb_size = load_ipynb_url(url, proxies=self.__get_proxies())
except RuntimeError as e:
logger.error(e)
return

changed_table_name_set = self._convert_nb(nb, source_info=source_info_record_base)

for table_name in changed_table_name_set:
Expand Down

0 comments on commit f599786

Please sign in to comment.