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

Getting errors while running in simple hurl file with :HurlVerbose #89

Closed
TimPelgrim opened this issue Feb 29, 2024 · 2 comments · Fixed by #94
Closed

Getting errors while running in simple hurl file with :HurlVerbose #89

TimPelgrim opened this issue Feb 29, 2024 · 2 comments · Fixed by #94
Labels

Comments

@TimPelgrim
Copy link

TimPelgrim commented Feb 29, 2024

Details

Have tried with multiple files, each resulting in the following error:

Error executing Lua callback: ...lgrim/.local/share/nvim/lazy/hurl.nvim/lua/hurl/main.lua:419: attempt to concatenate field 'start_line' (a nil value)
stack traceback:
	...lgrim/.local/share/nvim/lazy/hurl.nvim/lua/hurl/main.lua:419: in function <...lgrim/.local/share/nvim/lazy/hurl.nvim/lua/hurl/main.lua:390>

I installed with the basic config using LazyVim, specificly this lua file:

return {
  "jellydn/hurl.nvim",
  dependencies = { "MunifTanjim/nui.nvim" },
  ft = "hurl",
  opts = {
    -- Show debugging info
    debug = false,
    -- Show notification on run
    show_notification = false,
    -- Show response in popup or split
    mode = "split",
    -- Default formatter
    formatters = {
      json = { "jq" }, -- Make sure you have install jq in your system, e.g: brew install jq
      html = {
        "prettier", -- Make sure you have install prettier in your system, e.g: npm install -g prettier
        "--parser",
        "html",
      },
    },
  },
  keys = {
    -- Run API request
    { "<leader>A", "<cmd>HurlRunner<CR>", desc = "Run All requests" },
    { "<leader>a", "<cmd>HurlRunnerAt<CR>", desc = "Run Api request" },
    { "<leader>te", "<cmd>HurlRunnerToEntry<CR>", desc = "Run Api request to entry" },
    { "<leader>tm", "<cmd>HurlToggleMode<CR>", desc = "Hurl Toggle Mode" },
    { "<leader>tv", "<cmd>HurlVerbose<CR>", desc = "Run Api in verbose mode" },
    -- Run Hurl request in visual mode
    { "<leader>h", ":HurlRunner<CR>", desc = "Hurl Runner", mode = "v" },
  },
}```


<details open>
<summary>Checklist</summary>

- [X] Modify `lua/hurl/main.lua` ✓ https://github.com/jellydn/hurl.nvim/commit/fed85aa9c948dbff083e30212f8b568f03daa58f [Edit](https://github.com/jellydn/hurl.nvim/edit/sweep/getting_errors_while_running_in_simple_h/lua/hurl/main.lua#L419-L420)
- [ ] Running GitHub Actions for `lua/hurl/main.lua` ⋯  [Edit](https://github.com/jellydn/hurl.nvim/edit/sweep/getting_errors_while_running_in_simple_h/lua/hurl/main.lua#L419-L420)
</details>
Copy link
Contributor

sweep-ai bot commented Feb 29, 2024

🚀 Here's the PR! #90

See Sweep's progress at the progress dashboard!
Sweep Basic Tier: I'm using GPT-4. You have 5 GPT-4 tickets left for the month and 3 for the day. (tracking ID: a1a2415165)

For more GPT-4 tickets, visit our payment portal. For a one week free trial, try Sweep Pro (unlimited GPT-4 tickets).

Tip

I can email you next time I complete a pull request if you set up your email here!


Actions (click)

  • ↻ Restart Sweep

GitHub Actions✓

Here are the GitHub Actions logs prior to making any changes:

Sandbox logs for e3c0fb4
Checking lua/hurl/main.lua for syntax errors... ✅ lua/hurl/main.lua has no syntax errors! 1/1 ✓
Checking lua/hurl/main.lua for syntax errors...
✅ lua/hurl/main.lua has no syntax errors!

Sandbox passed on the latest main, so sandbox checks will be enabled for this issue.


Step 1: 🔎 Searching

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I think are relevant in decreasing order of relevance (click to expand). If some file is missing from here, you can mention the path in the ticket description.

FEATURES *hurl.nvim-features*
- 🚀 Execute HTTP requests directly from `.hurl` files.
- 👁‍🗨 Multiple display modes for API response: popup or split.
- 🌈 Highly customizable through settings.
USAGE *hurl.nvim-usage*
Add the following configuration to your Neovim setup with lazy.nvim
<https://github.com/folke/lazy.nvim>:
>lua
{
"jellydn/hurl.nvim",
dependencies = { "MunifTanjim/nui.nvim" },
ft = "hurl",
opts = {
-- Show debugging info
debug = false,
-- Show notification on run
show_notification = false,
-- Show response in popup or split
mode = "split",
-- Default formatter
formatters = {
json = { 'jq' }, -- Make sure you have install jq in your system, e.g: brew install jq
html = {
'prettier', -- Make sure you have install prettier in your system, e.g: npm install -g prettier
'--parser',
'html',
},
},
},
keys = {
-- Run API request
{ "<leader>A", "<cmd>HurlRunner<CR>", desc = "Run All requests" },
{ "<leader>a", "<cmd>HurlRunnerAt<CR>", desc = "Run Api request" },
{ "<leader>te", "<cmd>HurlRunnerToEntry<CR>", desc = "Run Api request to entry" },
{ "<leader>tm", "<cmd>HurlToggleMode<CR>", desc = "Hurl Toggle Mode" },
{ "<leader>tv", "<cmd>HurlVerbose<CR>", desc = "Run Api in verbose mode" },
-- Run Hurl request in visual mode
{ "<leader>h", ":HurlRunner<CR>", desc = "Hurl Runner", mode = "v" },
},
}
<

hurl.nvim/lua/hurl/main.lua

Lines 388 to 421 in e3c0fb4

-- Run Hurl in verbose mode and send output to quickfix
utils.create_cmd('HurlVerbose', function(opts)
-- It should be the same logic with run at current line but with verbose flag
-- The response will be sent to quickfix
local result = http.find_http_verb_positions_in_buffer()
if result.current > 0 and result.start_line and result.end_line then
utils.log_info(
'hurl: running request at line ' .. result.start_line .. ' to ' .. result.end_line
)
opts.fargs = opts.fargs or {}
opts.fargs = vim.list_extend(opts.fargs, { '--verbose' })
-- Clear quickfix list
vim.fn.setqflist({}, 'r', {
title = 'hurl',
lines = {},
})
run_at_lines(result.start_line, result.end_line, opts.fargs, function(code, data, event)
utils.log_info('hurl: verbose callback ' .. vim.inspect(code) .. vim.inspect(data))
vim.fn.setqflist({}, 'a', {
title = 'hurl - data',
lines = data,
})
vim.fn.setqflist({}, 'a', {
title = 'hurl - event',
lines = event,
})
vim.cmd('copen')
end)
else
utils.log_info('hurl: not HTTP method found in the current line' .. result.start_line)
utils.notify('hurl: no HTTP method found in the current line', vim.log.levels.INFO)
end


Step 2: ⌨️ Coding

Modify lua/hurl/main.lua with contents:
• To prevent the attempt to concatenate a nil value and to handle the error more gracefully, change the log and notification lines to check if `result.start_line` is nil before using it. If `result.start_line` is nil, provide a generic message that does not attempt to use it.
• Replace the existing lines 419 and 420 with the following code snippet: ```lua if result.start_line then utils.log_info('hurl: not HTTP method found in the current line ' .. result.start_line) else utils.log_info('hurl: no HTTP method found in the current line') end utils.notify('hurl: no HTTP method found in the current line', vim.log.levels.INFO) ```
• This change ensures that if `result.start_line` is nil, the code does not attempt to concatenate it, thus avoiding the error. It also provides a clear notification to the user that no HTTP method was found in the current line, regardless of whether `result.start_line` is nil.
--- 
+++ 
@@ -353,7 +353,11 @@
       )
       run_at_lines(result.start_line, result.end_line, opts.fargs)
     else
-      utils.log_info('hurl: not HTTP method found in the current line' .. result.start_line)
+      if result.start_line then
+        utils.log_info('hurl: not HTTP method found in the current line ' .. result.start_line)
+      else
+        utils.log_info('hurl: no HTTP method found in the current line')
+      end
       utils.notify('hurl: no HTTP method found in the current line', vim.log.levels.INFO)
     end
   end, { nargs = '*', range = true })
@@ -416,7 +420,11 @@
         vim.cmd('copen')
       end)
     else
-      utils.log_info('hurl: not HTTP method found in the current line' .. result.start_line)
+      if result.start_line then
+        utils.log_info('hurl: not HTTP method found in the current line ' .. result.start_line)
+      else
+        utils.log_info('hurl: no HTTP method found in the current line')
+      end
       utils.notify('hurl: no HTTP method found in the current line', vim.log.levels.INFO)
     end
   end, { nargs = '*', range = true })
  • Running GitHub Actions for lua/hurl/main.luaEdit
Check lua/hurl/main.lua with contents:

Ran GitHub Actions for fed85aa9c948dbff083e30212f8b568f03daa58f:
• pandoc to vimdoc:


Step 3: 🔁 Code Review

I have finished reviewing the code for completeness. I did not find errors for sweep/getting_errors_while_running_in_simple_h.


🎉 Latest improvements to Sweep:
  • New dashboard launched for real-time tracking of Sweep issues, covering all stages from search to coding.
  • Integration of OpenAI's latest Assistant API for more efficient and reliable code planning and editing, improving speed by 3x.
  • Use the GitHub issues extension for creating Sweep issues directly from your editor.

💡 To recreate the pull request edit the issue title or description. To tweak the pull request, leave a comment on the pull request.Something wrong? Let us know.

This is an automated message generated by Sweep AI.

@jellydn
Copy link
Owner

jellydn commented Mar 1, 2024

Hi @TimPelgrim Thank you for your report. Could you check again with latest version? It should work now.

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