diff --git a/spacy/errors.py b/spacy/errors.py index 937596d5d..bfdf71652 100644 --- a/spacy/errors.py +++ b/spacy/errors.py @@ -408,6 +408,7 @@ class Errors(object): E143 = ("Labels for component '{name}' not initialized. Did you forget to call add_label()?") E144 = ("Could not find parameter `{param}` when building the entity linker model.") E145 = ("Error reading `{param}` from input file.") + E146 = ("Could not access `{path}`.") @add_codes diff --git a/spacy/kb.pyx b/spacy/kb.pyx index a300ed34a..28e762653 100644 --- a/spacy/kb.pyx +++ b/spacy/kb.pyx @@ -372,7 +372,8 @@ cdef class Writer: loc = bytes(loc) cdef bytes bytes_loc = loc.encode('utf8') if type(loc) == unicode else loc self._fp = fopen(bytes_loc, 'wb') - assert self._fp != NULL, "Could not access %s" % loc + if not self._fp: + raise IOError(Errors.E146.format(path=loc)) fseek(self._fp, 0, 0) def close(self):