Skip to content

Commit

Permalink
fix(hoogle-web): error handling for invalid curl output (#323)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb authored Jan 10, 2024
1 parent 9e7c05c commit d1347d9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
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

0 comments on commit d1347d9

Please sign in to comment.