New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
box.errors: add "__concat" metamethod #4489
Comments
It is box.error object and you can, say, look into a lua backtrace with e.trace. Sooner or later we should use it for all errors that comes from tarantool I think. See also #4398. |
Could we redefine |
I propose following patch to close this issue From 55b2fd6983d415f8924c10ecf1949db1f1ae6e9f Mon Sep 17 00:00:00 2001
From: Oleg Babin
Date: Wed, 11 Sep 2019 18:53:56 +0300
Subject: [PATCH] error: Add __concat method to error object
Usually functions return pair {nil, err} and user expects that err is string.
Let's make the behaviour of error object closer to string
and define __concat metamethod.
Closes tarantool/tarantool#4489
---
src/lua/error.lua | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/src/lua/error.lua b/src/lua/error.lua
index 28fc0377d..b44fab7b6 100644
--- a/src/lua/error.lua
+++ b/src/lua/error.lua
@@ -150,9 +150,17 @@ local function error_index(err, key)
return error_methods[key]
end
+local function error_concat(lhs, rhs)
+ if lhs == nil or rhs == nil then
+ error("attempt to concatenate struct error and nil")
+ end
+ return tostring(lhs) .. tostring(rhs)
+end
+
local error_mt = {
__index = error_index;
__tostring = error_message;
+ __concat = error_concat;
};
ffi.metatype('struct error', error_mt);
--
2.22.0
That do you think about it? |
I would say that it should not allow more then a string: say, I think it is harmless, so I'm okay in general. |
@kyukhin If it is considered as a bug, then it worth to set 1.10.6 milestone? |
Usually functions return pair `nil, err` and expected that err is string. Let's make the behaviour of error object closer to string and define __concat metamethod. The case of error "error_mt.__concat(): neither of args is an error" is not covered by tests because of #4723 Closes #4489 (cherry picked from commit 935db17)
Usually functions return pair `nil, err` and expected that err is string. Let's make the behaviour of error object closer to string and define __concat metamethod. The case of error "error_mt.__concat(): neither of args is an error" is not covered by tests because of #4723 Closes #4489 (cherry picked from commit 935db17)
Usually functions return pair `nil, err` and expected that err is string. Let's make the behaviour of error object closer to string and define __concat metamethod. The case of error "error_mt.__concat(): neither of args is an error" is not covered by tests because of #4723 Closes #4489 (cherry picked from commit 935db17)
I've changed issue title - to clarify that was done in fact |
Usually functions return pair `nil, err` and expected that err is string. Let's make the behaviour of error object closer to string and define __concat metamethod. The case of error "error_mt.__concat(): neither of args is an error" is not covered by tests because of tarantool#4723 Closes tarantool#4489
Follow-up: #4044
Please, check that all fio functions return error as string
The text was updated successfully, but these errors were encountered: