stevearc / conform.nvim

Lightweight yet powerful formatter plugin for Neovim
MIT License
2.55k stars 135 forks source link

bug: prettierd formatter does not show error message #486

Open powerman opened 3 days ago

powerman commented 3 days ago

Neovim version (nvim -v)

v0.10.0

Operating system/version

Gentoo Linux

Add the debug logs

Log file

Without DEBUG log level:

04:03:52[ERROR] Formatter 'prettierd' error:

With DEBUG log level:

04:05:21[DEBUG] Running formatters on /home/powerman/tmp/bug-nvim-conform-prettierd/test.html: { "prettierd" }
04:05:21[INFO] Run prettierd on /home/powerman/tmp/bug-nvim-conform-prettierd/test.html
04:05:21[DEBUG] Run command: { "/home/powerman/node_modules/.bin/prettierd", "/home/powerman/tmp/bug-nvim-conform-prettierd/test.html" }
04:05:21[DEBUG] Run CWD: /home/powerman
04:05:21[INFO] prettierd exited with code 1
04:05:21[DEBUG] prettierd stdout: { 'SyntaxError: Unexpected closing tag "p". It may happen when the tag has already been closed by another tag. For more info see https://www.w3.org/TR/html5/syntax.html#closing-elements-that-have-implied-end-tags (1:15)', "\27[0m\27[31m\27[1m>\27[22m\27[39m\27[90m 1 |\27[39m \27[33m<\27[39m\27[33mp\27[39m\27[33m>\27[39m\27[33m<\27[39m\27[33mpre\27[39m\27[33m>\27[39m\27[33m<\27[39m\27[33m/\27[39m\27[33mpre\27[39m\27[33m>\27[39m\27[33m<\27[39m\27[33m/\27[39m\27[33mp\27[39m\27[33m>\27[39m", " \27[90m   |\27[39m               \27[31m\27[1m^\27[22m\27[39m\27[31m\27[1m^\27[22m\27[39m\27[31m\27[1m^\27[22m\27[39m\27[31m\27[1m^\27[22m\27[39m", " \27[90m 2 |\27[39m\27[0m", "" }
04:05:21[DEBUG] prettierd stderr: { "" }
04:05:21[ERROR] Formatter 'prettierd' error: 

Describe the bug

Without DEBUG log level :ConformInfo does not show actual error message: изображение

As it became clear from log with DEBUG log level the real problem is prettierd output error to STDOUT instead of STDERR plus use colored output. изображение

What is the severity of this bug?

tolerable (can work around it)

Steps To Reproduce

  1. Create file test.html with content provided below.
  2. nvim -u repro.lua test.html
  3. :lua require('conform').format()
  4. :ConformInfo
  5. With DEBUG log level you'll see error message but it'll be unreadable, without DEBUG there will be no error message at all.

Expected Behavior

prettierd error should be included in :ConformInfo output with ERROR log level and without terminal escape-sequences.

Minimal example file

<p><pre></pre></p>

Minimal init.lua

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "--single-branch",
    "https://github.com/folke/lazy.nvim.git",
    lazypath,
  })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
  {
    "stevearc/conform.nvim",
    config = function()
      require("conform").setup({
        log_level = vim.log.levels.DEBUG,
        -- add your config here
        formatters_by_ft = {
            html = { "prettierd" },
        },
      })
    end,
  },
  -- add any other plugins here
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here

Additional context

No response

powerman commented 3 days ago

https://github.com/fsouza/prettierd/issues/611#issuecomment-2204855421