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

fix(hoogle-web): error handling for invalid curl output #323

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.1.2] - 2024-01-10

### Fixed

- Hoogle (web): Error handling for invalid `curl` output [[#322](https://github.com/mrcjkb/haskell-tools.nvim/issues/322)].

## [3.1.1] - 2023-12-22

### Fixed
Expand Down
14 changes: 12 additions & 2 deletions lua/haskell-tools/hoogle/web.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,26 @@ if deps.has_telescope() then
opts.hoogle = opts.hoogle or {}
opts.hoogle.json = true
local url = mk_hoogle_request(search_term, opts)
compat.system({ 'curl', '--silent', url, '-H', 'Accept: application/json' }, nil, function(result)
local curl_command = { 'curl', '--silent', url, '-H', 'Accept: application/json' }
log.debug(curl_command)
compat.system(curl_command, nil, function(result)
---@cast result vim.SystemCompleted
log.debug { 'Hoogle web response', result }
local response = result.stdout
if result.code ~= 0 or response == nil then
vim.notify('hoogle web: ' .. (result.stderr or 'error calling curl'), vim.log.levels.ERROR)
return
end
local results = vim.json.decode(response)
local ok, results = pcall(vim.json.decode, response)
vim.schedule(function()
if not ok then
log.error { 'Hoogle web response (invalid JSON)', curl_command, 'result: ' .. result }
vim.notify(
"haskell-tools.hoogle: Received invalid JSON from curl. Likely due to a failed request. See ':HtLog' for details'",
vim.log.levels.ERROR
)
return
end
pickers
.new(opts, {
prompt_title = 'Hoogle: ' .. search_term,
Expand Down
Loading