diff --git a/src/lua/buffer.lua b/src/lua/buffer.lua index a05b6af00a7d93b42425de55af7fdf674abe823a..c5cefe32b60c029bde0bcf606b2565985bff1f89 100644 --- a/src/lua/buffer.lua +++ b/src/lua/buffer.lua @@ -227,8 +227,8 @@ local prbuf_entry_t = ffi.typeof('struct prbuf_entry') local function prbuf_open(mem) if not ffi.istype(ffi.typeof('char *'), mem) then - errorf('Attempt to prbuf_open() with argument of wrong type %s', - ffi.typeof(mem)) + errorf('Attempt to prbuf_open() with argument of wrong type, '.. + 'expected <char *>') end local buf = ffi.new(prbuf_t) local rc = builtin.prbuf_open(buf, mem) @@ -240,8 +240,8 @@ end local function prbuf_create(mem, size) if not ffi.istype(ffi.typeof('char *'), mem) then - errorf('Attempt to prbuf_open() with argument of wrong type %s', - ffi.typeof(mem)) + errorf('Attempt to prbuf_create() with argument of wrong type, '.. + 'expected <char *>') end local buf = ffi.new(prbuf_t) builtin.prbuf_create(buf, mem, size) diff --git a/test/app-luatest/prbuf_test.lua b/test/app-luatest/prbuf_test.lua index 477e52417293a8ab6a5eacf43e247004139c7b41..8810b8551a53745064f870f1d2d3b40557911fdf 100644 --- a/test/app-luatest/prbuf_test.lua +++ b/test/app-luatest/prbuf_test.lua @@ -1,4 +1,5 @@ local buffer = require('buffer') +local ffi = require('ffi') local t = require('luatest') local g = t.group() @@ -45,3 +46,18 @@ g.test_object_misc = function() end t.assert_equals(entry_count, 5) end + +g.test_wrong_arg_type = function() + local int = ffi.new('int') + local map = {} + local status, err = pcall(buffer.prbuf_create, int, 4) + local expected_err = 'Attempt to prbuf_create%(%) with argument '.. + 'of wrong type, expected %<char %*%>' + t.assert_equals(status, false) + t.assert_equals(string.find(tostring(err), expected_err) ~= nil, true) + expected_err = 'Attempt to prbuf_open%(%) with argument '.. + 'of wrong type, expected %<char %*%>' + local status, err = pcall(buffer.prbuf_open, map, 4) + t.assert_equals(status, false) + t.assert_equals(string.find(tostring(err), expected_err) ~= nil, true) +end