Skip to content

Error on unsupported #211

Closed
Closed

Description

@ignamartinoli

Hey, really nice plugin, I love using it.
The other day I tried to use it on a JSON file. I forgot it wasn't possible to comment JSON, but after I did I received this error message:

E5108: Error executing lua Vim(lua):E5108: Error executing lua .../site/pack/packer/opt/Comment.nvim/lua/Comment/utils.lua:156: [Comment] Invalid commentstring - "". Run :h 'commentstring' for help.
stack traceback:
        [C]: in function 'assert'
        .../site/pack/packer/opt/Comment.nvim/lua/Comment/utils.lua:156: in function 'parse_cstr'
        ...site/pack/packer/opt/Comment.nvim/lua/Comment/optfunc.lua:62: in function 'opfunc'
        ...im/site/pack/packer/opt/Comment.nvim/lua/Comment/api.lua:279: in function 'current'
        [string ":lua"]:1: in main chunk
        [C]: at 0x55d7ba838e46
stack traceback:
        [C]: at 0x55d7ba838e46

It's totally correct for the plugin to refuse to comment in a language that hasn't that feature.
But what I would suggest is avoiding to crash and break the user experience.
The plugin could show a yellow message under the statusline with something like

Comment.nvim: commenting unsupported

For example, in nvim-lspconfig, when a Language Server crashes, it's reported this way.

Thanks for your time and your awesome plugin

Activity

  1. numToStr commented on Aug 21, 2022

    @numToStr
    Owner

    Here's my take:

    The plugin could show a yellow message under the statusline with something like

    commenting unsupported doesn't provide any info on why the filetype is not supported. So I believe the current error message is very clear and helpful.

    But what I would suggest is avoiding to crash and break the user experience.

    It's "impossible" to get this error/crash unless you try something funny like comment json or text file, which i would call undefined behavior, in that case this panic make sense to me. And second reason for using assert here is to keep the code simple, rather than checking for commentstring at multiple places, i let it panic and abort the current function execution.

    function U.parse_cstr(cfg, ctx)
    this is the function, and it is used at 4 different places.

  2. Repository owner locked and limited conversation to collaborators on Aug 21, 2022
  3. converted this issue into a discussion #212 on Aug 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions