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

TypeError is raised instead of Meilisearch::ApiError on invalid filter to documents api #513

Closed
matt-cassidy opened this issue Jan 16, 2024 · 3 comments · Fixed by #515
Closed
Assignees
Labels
bug Something isn't working

Comments

@matt-cassidy
Copy link

Description
If you use the client to find documents using a filter that would have a syntax error the MeilisearchError::ApiError is no longer raised but instead of TypeError is raised. We would capture the MeilisearchError::ApiError to capture the error message to help inform the user what went wrong.

Expected behavior
That the appropriate MeilisearchError::ApiError is raised

Current behavior
A TypeError of "no implicit conversion of Hash into String"

Screenshots or Logs
Here is a sample script I used to reduce the problem down

client = MeiliSearch::Client.new('http://localhost:7700', ENV['MEILISEARCH_API_KEY'])

index_name = 'catch-error-issue'
create_task = client.create_index(index_name, primary_key: :id)
settings_task = client.index(index_name).update_settings({
  searchable_attributes: [:test_filter],
  filterable_attributes: [:id, :test_filter]
})
client.wait_for_task(create_task['taskUid'])
client.wait_for_task(settings_task['taskUid'])

begin
  result = client.index(index_name).get_documents({filter: 'x ! 3'})
rescue MeiliSearch::ApiError => e
  err = e
rescue StandardError => e
  err = e
end

err.class == MeiliSearch::ApiError

Results

=> "catch-error-issue"
=> {"taskUid"=>29, "indexUid"=>"catch-error-issue", "status"=>"enqueued", "type"=>"indexCreation", "enqueuedAt"=>"2024-01-16T15:12:28.729044Z"}
=> {"taskUid"=>30, "indexUid"=>"catch-error-issue", "status"=>"enqueued", "type"=>"settingsUpdate", "enqueuedAt"=>"2024-01-16T15:12:28.753813Z"}
=> {"uid"=>29, "indexUid"=>"catch-error-issue", "status"=>"succeeded", "type"=>"indexCreation", "canceledBy"=>nil, "details"=>{"primaryKey"=>"id"}, "error"=>nil, "duration"=>"PT0.007108S", "enqueuedAt"=>"2024-01-16T15:12:28.729044Z", "startedAt"=>"2024-01-16T15:12:28.729823Z", "finishedAt"=>"2024-01-16T15:12:28.736931Z"}
=> {"uid"=>30, "indexUid"=>"catch-error-issue", "status"=>"succeeded", "type"=>"settingsUpdate", "canceledBy"=>nil, "details"=>{"searchableAttributes"=>["test_filter"], "filterableAttributes"=>["id", "test_filter"]}, "error"=>nil, "duration"=>"PT0.002684S", "enqueuedAt"=>"2024-01-16T15:12:28.753813Z", "startedAt"=>"2024-01-16T15:12:28.75465Z", "finishedAt"=>"2024-01-16T15:12:28.757334Z"}
=> #<TypeError: no implicit conversion of Hash into String>
=> false

Backtrace

/gems/json-2.5.1/lib/json/common.rb:216:in `initialize'
/gems/json-2.5.1/lib/json/common.rb:216:in `new'
/gems/json-2.5.1/lib/json/common.rb:216:in `parse'
/gems/meilisearch-0.26.0/lib/meilisearch/error.rb:34:in `get_meilisearch_error_info'
/gems/meilisearch-0.26.0/lib/meilisearch/error.rb:24:in `initialize'
/gems/meilisearch-0.26.0/lib/meilisearch/utils.rb:51:in `new'
/gems/meilisearch-0.26.0/lib/meilisearch/utils.rb:51:in `rescue in version_error_handler'
/gems/meilisearch-0.26.0/lib/meilisearch/utils.rb:46:in `version_error_handler'
/gems/meilisearch-0.26.0/lib/meilisearch/index.rb:77:in `documents'

Environment (please complete the following information):

  • OS: [MacOS 12.7]
  • Meilisearch version: [v.1.4.0] and [v.1.6.0]
  • meilisearch-ruby version: [v0.26.0]
@ellnix
Copy link
Collaborator

ellnix commented Jan 17, 2024

Thank you very much for this bug report. There seems to be a logic problem in version_error_handler, I will fix it and update the specs as soon as I can.

@ellnix ellnix self-assigned this Jan 17, 2024
@ellnix ellnix added the bug Something isn't working label Jan 17, 2024
@ellnix
Copy link
Collaborator

ellnix commented Jan 17, 2024

If you have time, please try to reproduce this issue on the new PR linked to this issue. For me the PR fixes it.

@matt-cassidy
Copy link
Author

@ellnix I tried replicating the bug using your branch and the issue no longer occurs 👍

@meili-bors meili-bors bot closed this as completed in 5e2d354 Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants