Skip to content

Formatting empty body with jq results in unhandled error #478

@jrebs

Description

@jrebs

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 },
            },
        },
    },
})

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions