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

Formatting empty body with jq results in unhandled error #478

Closed
2 tasks done
jrebs opened this issue Sep 30, 2024 · 1 comment · Fixed by #479 or #480
Closed
2 tasks done

Formatting empty body with jq results in unhandled error #478

jrebs opened this issue Sep 30, 2024 · 1 comment · Fixed by #479 or #480
Assignees
Labels
bug Something isn't working

Comments

@jrebs
Copy link

jrebs commented Sep 30, 2024

Prerequisites

  • I am using the latest stable release of Neovim
  • I am using the latest version of the plugin

Neovim Version

v0.10.1

Operating system/version

Xubuntu 24.04

Actual behavior

When a request results in a 401 with an empty body, rest.vim dumps a big error trace to the user and gets stuck in a "Loading..." status that never shows the user what the response code of the request was, making it difficult to diagnose.

image

image

Expected behavior

The expectation would be that if there is no body to be formatted, rest.nvim would skip the formatting step and this would give the user a results pane that would look like:

HTTP/2 401

# @_RES

# @_END

Steps to reproduce

Run this request with

# GET Test that will return an 401 response with no body content                                          
GET https://api.attentivemobile.com/v1/me

Other information

When using the "Repro" script below, rest.nvim does not yield the error above. Instead it yields the expected result due to the fact that there is no formatting occurring on the response. If I use the repro code and request a working endpoint with valid token, I get back an expected response, but the JSON is not formatted and is just a big long string that is difficult to read.

To get formatting to work, I followed the guidance from boltlessengineer here: #414 (comment).

That recommendation causes the rest responses to be formatted and highlighted in pretty JSON, but seems to have the side effect of rest.nvim not handling the error nicely when there is no body to format.

Repro (lazy.nvim)

vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()

require("lazy.minit").repro({
    spec = {
        "rest-nvim/rest.nvim",
        {
            "nvim-treesitter/nvim-treesitter",
            build = ":TSUpdate",
            main = "nvim-treesitter.configs",
            opts = {
                ensure_installed = { "http" },
                sync_install = false,
                highlight = { enable = true },
                indent = { enable = true },
            },
        },
    },
})
@jrebs jrebs added the bug Something isn't working label Sep 30, 2024
@boltlessengineer
Copy link
Contributor

Can reproduce it. Thank you for reporting with that precise reproduce steps :)

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
2 participants