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

Strange "hyperscan.InvalidError: error code -1" #50

Open
jerzyorlowskimim opened this issue Jan 16, 2023 · 6 comments
Open

Strange "hyperscan.InvalidError: error code -1" #50

jerzyorlowskimim opened this issue Jan 16, 2023 · 6 comments
Assignees

Comments

@jerzyorlowskimim
Copy link

I got strange hyperscan.InvalidError: error code -1 while using scan() function.
There nothing else in the stack trace and I cannot find any clue in google

It looks like some stupid simple error. Any Idea what it might be?
Is it possible to make the error message more elaborate?

@jerzyorlowskimim
Copy link
Author

I am using hyperscan version 0.4.0

@jerzyorlowskimim
Copy link
Author

jerzyorlowskimim commented Jan 16, 2023

Steps:

f = open("local/keyword_features_hyperscan_databases/TestKeyword1", 'rb')
hdb = hyperscan.loadb(f.read())
hdb.scan("aaa")

gives:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: a bytes-like object is required

TestKeyword1 is a simple test database with a few words that is being compiled a moment before during tests.

@darvid
Copy link
Owner

darvid commented Jan 16, 2023

try hdb.scan(b"aaa")

@jerzyorlowskimim
Copy link
Author

hdb.scan(b"aaa") didn't help. But switching back to hyperscan version 0.3.3 solved the issue.

@darvid darvid self-assigned this Jan 16, 2023
@darvid darvid added the bug label Jan 16, 2023
jerzyorlowskimim added a commit to mim-solutions/MIM-OCR that referenced this issue Jan 17, 2023
hyperscan version freezed at 0.3.3 due to darvid/python-hyperscan#50
@darvid
Copy link
Owner

darvid commented Jan 17, 2023

going to improve type annotations and tests to cover this, as well as docs, but basically the issue is the returned Database doesn't include a scratch. try this:

hdb.scratch = hyperscan.Scratch(db)
hdb.scan(b"aaa")

also you'll have to keep track of the mode of the database that the serialized representation was created with. i.e. if it was created with stream mode, you'll have to use the stream context manager. currently db.mode isn't set on the returned db object, which I'll try to fix.

@darvid darvid added enhancement and removed bug labels Jan 17, 2023
@michaelmior
Copy link

michaelmior commented Jun 7, 2023

@darvid Is there any reason that the scratch can't (or shouldn't) be initialized automatically if it's missing? At minimum, it would obviously help to have a more informative error :)

(Also, it looks like there's a small typo in your code example above where the parameter to the Scratch constructor should be hdb instead of db.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants