Ignore binary files in code search to prevent Error 500
Leaving out the -I option in "git grep" would cause an Error 500 because the resulting line would include "Binary file X matches", which would cause the project search results to crash with the following error:
ActionView::Template::Error (wrong argument type nil (expected Regexp)):
1: - blob = @project.repository.parse_search_result(blob)
2: .blob-result
3: .file-holder
4: .file-title
app/models/repository.rb:742:in `sub'
app/models/repository.rb:742:in `block in parse_search_result_from_grep'
app/models/repository.rb:741:in `each_line'
app/models/repository.rb:741:in `parse_search_result_from_grep'
app/models/repository.rb:682:in `parse_search_result'
app/views/search/results/_blob.html.haml:1:in `_app_views_search_results__blob_html_haml__1959871337755590783_162450160'
app/views/search/_results.html.haml:20:in `_app_views_search__results_html_haml__2198486911700532411_58329920'
app/views/search/show.html.haml:7:in `_app_views_search_show_html_haml___1698304427272645201_62235300'
Merge request reports
Activity
Reassigned to @dzaporozhets
@stanhu thank you
mentioned in commit dc78ee4e
@stanhu @dzaporozhets would there be any interest in handling the 'Binary file ... matches' cases and just outputting that the file matched, but no preview is available?
Thanks for your consideration
@atavakoli How useful is searching binary files for you? I think it could probably be added with relative ease for the
git grep
case, but I doubt we'd want to index binary files in Elasticsearch to match this functionality.@stanhu @dzaporozhets thanks guys, I suspected as much, and to be honest I don't use git's binary matching very frequently.
WRT usefulness of indexing binary files in general, we use GitLab for both code & documentation (including docx/pdf/xlsx files), and having these types of files' contents searchable in Elastic would be very useful (and I believe Elastic already supports this via a plugin). I'm not sure if there are already plans for this, and I didn't see any existing issues. If you think this might help others too, I can open a feature request.
Thanks!
@atavakoli thank you for understanding. Feel free to open feature request if you think its something people might need as well