mirror of
https://github.com/explosion/spaCy.git
synced 2025-01-24 00:04:15 +03:00
Add error message if DocBin zlib decompress fails (#6394)
Add a better error message if DocBin zlib decompress fails, indicating that the data is not in `DocBin` format.
This commit is contained in:
parent
165993d8e5
commit
26296ab223
|
@ -712,6 +712,10 @@ class Errors:
|
|||
E1013 = ("Invalid morph: the MorphAnalysis must have the same vocab as the "
|
||||
"token itself. To set the morph from this MorphAnalysis, set from "
|
||||
"the string value with: `token.set_morph(str(other_morph))`.")
|
||||
E1014 = ("Error loading DocBin data. It doesn't look like the data is in "
|
||||
"DocBin (.spacy) format. If your data is in spaCy v2's JSON "
|
||||
"training format, convert it using `python -m spacy convert "
|
||||
"file.json .`.")
|
||||
|
||||
|
||||
# Deprecated model shortcuts, only used in errors and warnings
|
||||
|
|
|
@ -198,7 +198,10 @@ class DocBin:
|
|||
|
||||
DOCS: https://nightly.spacy.io/api/docbin#from_bytes
|
||||
"""
|
||||
msg = srsly.msgpack_loads(zlib.decompress(bytes_data))
|
||||
try:
|
||||
msg = srsly.msgpack_loads(zlib.decompress(bytes_data))
|
||||
except zlib.error:
|
||||
raise ValueError(Errors.E1014)
|
||||
self.attrs = msg["attrs"]
|
||||
self.strings = set(msg["strings"])
|
||||
lengths = numpy.frombuffer(msg["lengths"], dtype="int32")
|
||||
|
|
Loading…
Reference in New Issue
Block a user