Skip to content

An annotation for indicating that a function may error #2400

@Delta-official

Description

@Delta-official

It would be pretty useful to have an indicator of whether the function may error (and thus needs to be handled with pcall or the like).

---@fallible
---@param bar string
---@return string bar
local function assert_is_foobar(bar)
    if bar ~= "foobar" then
        error("bar isn't equal to foobar")
    end
    return bar
end

I'm aware of #1881 but it doesn't fullfill the same purpose as @fallible, the main difference being the fact that @noreturn indicates that the function never returns while this indicates that the function could return an error

The LSP server could also potentially show the user a warning if they don't wrap a @fallible function in a pcall call

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions