A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/neovim/neovim/commit/81bffbd147cd24580ac92fa9d9d85121151ca01f below:

call __tostring on lua errors if possible before reporting to user · neovim/neovim@81bffbd · GitHub

@@ -61,6 +61,44 @@ describe('print', function()

61 61

eq('Vim(lua):E5108: Error executing lua E5114: Error while converting print argument #2: <Unknown error: lua_tolstring returned NULL for tostring result>',

62 62

pcall_err(command, 'lua print("foo", v_tblout, "bar")'))

63 63

end)

64 +

it('coerces error values into strings', function()

65 +

write_file(fname, [[

66 +

function string_error() error("my mistake") end

67 +

function number_error() error(1234) end

68 +

function nil_error() error(nil) end

69 +

function table_error() error({message = "my mistake"}) end

70 +

function custom_error()

71 +

local err = {message = "my mistake", code = 11234}

72 +

setmetatable(err, {

73 +

__tostring = function(t)

74 +

return "Internal Error [" .. t.code .. "] " .. t.message

75 +

end

76 +

})

77 +

error(err)

78 +

end

79 +

function bad_custom_error()

80 +

local err = {message = "my mistake", code = 11234}

81 +

setmetatable(err, {

82 +

-- intentionally not a function, downstream programmer has made an mistake

83 +

__tostring = "Internal Error [" .. err.code .. "] " .. err.message

84 +

})

85 +

error(err)

86 +

end

87 +

]])

88 +

eq('', exec_capture('luafile ' .. fname))

89 +

eq('Vim(lua):E5108: Error executing lua Xtest-functional-lua-overrides-luafile:0: my mistake',

90 +

pcall_err(command, 'lua string_error()'))

91 +

eq('Vim(lua):E5108: Error executing lua Xtest-functional-lua-overrides-luafile:0: 1234',

92 +

pcall_err(command, 'lua number_error()'))

93 +

eq('Vim(lua):E5108: Error executing lua [NULL]',

94 +

pcall_err(command, 'lua nil_error()'))

95 +

eq('Vim(lua):E5108: Error executing lua [NULL]',

96 +

pcall_err(command, 'lua table_error()'))

97 +

eq('Vim(lua):E5108: Error executing lua Internal Error [11234] my mistake',

98 +

pcall_err(command, 'lua custom_error()'))

99 +

eq('Vim(lua):E5108: Error executing lua [NULL]',

100 +

pcall_err(command, 'lua bad_custom_error()'))

101 +

end)

64 102

it('prints strings with NULs and NLs correctly', function()

65 103

meths.set_option('more', true)

66 104

eq('abc ^@ def\nghi^@^@^@jkl\nTEST\n\n\nT\n',


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4