-
Notifications
You must be signed in to change notification settings - Fork 34
Function name and line number in logs and exceptions #742
Conversation
d1ee2d1 to
23f2544
Compare
Done automatically with script published in: tango-controls#742
What we had was broken as if one of the strings was empty the other one was truncated to 0 size as well.
Due to broken comparator implementation (see previous commit), this test was never correct.
The log messages now contain file name and line number. Comparator must be extended to support this scenario.
Done automatically with sed. See script published in: tango-controls#742
Done automatically with script published in: tango-controls#742
bd453fe to
63eaac7
Compare
|
Large commit "Define constants for API exception reasons" (23bba98) was done mostly automatically: rm cppapi/server/tango_const.h.in
for e in `rg '"API_.*?"' -o -I -N | sort | uniq | sed 's/.$//' | cut -c 2-`; do
find . -name '*.cpp' -o -name '*.tpp' -o -name '*.h' | xargs -I{} sed -i 's|"'$e'"|'$e'|g' {}
done
git checkout cppapi/server/tango_const.h.in
rg 'API_[A-Z][a-z][a-zA-Z]+' -o -I -N | sort | uniq | xargs -I{} echo 'const char* const {} = "{}";'
# replace definitions in tango_const.h.in with output of the above command
# fix broken compilation where needed |
|
Large commit "Replace Except::throw_exception with macro" (63eaac7) was done mostly automatically with following scripts: for f in `rg -l -e '::throw_exception' -e '::re_throw_exception'`; do
echo "patching $f"
python ../rename.py $f > $f.tmp
mv $f.tmp $f
done
# to remove extra newlines (forgot about that in rename script
for f in `rg TANGO_THROW_ -l`; do sed -i -e '/TANGO_THROW_/{n;d}' $f; done
# same for RETHROWChanges to these were reverted: Changes in these required manual corrections: Rename script: import re
import sys
SEARCH_THROW = '::throw_exception'
SEARCH_RETHROW = '::re_throw_exception'
FLUSH = object()
def Parser():
buff = ""
while True:
c = yield
if (c is FLUSH):
print(buff, end='')
buff = ""
continue
buff += c
if c.isspace():
print(buff, end='')
buff = ""
continue
if buff.endswith(SEARCH_THROW) or buff.endswith(SEARCH_RETHROW):
api_obj, _method = buff.rsplit("::", maxsplit=1)
api = not bool(re.match(r"^(::)?(Tango)?(::)?Except", api_obj))
rethrow = buff.endswith(SEARCH_RETHROW)
buff = ""
arg_buff = ""
args = []
yield # opening brace
while True:
c = yield
if c == ";":
args.append(arg_buff[:-1]) # closing brace
break
if c == ",":
args.append(arg_buff)
arg_buff = ""
continue
if c == '"':
arg_buff += c
while True:
c = yield
arg_buff += c
if c == '"':
break
continue
arg_buff += c
args = [s.replace("(const char *)", "") for s in args]
args = [s.replace("(const char*)", "") for s in args]
args = [s.strip() for s in args]
if rethrow:
assert len(args) == 4
if api:
print("TANGO_RETHROW_API_EXCEPTION({}, {}, {}, {});".format(
api_obj, args[0], args[1], args[2]))
else:
print("TANGO_RETHROW_EXCEPTION({}, {}, {});".format(
args[0], args[1], args[2]))
else:
assert len(args) == 3
if api:
print("TANGO_THROW_API_EXCEPTION({}, {}, {});".format(
api_obj, args[0], args[1]))
else:
print("TANGO_THROW_EXCEPTION({}, {});".format(
args[0], args[1]))
parser = Parser()
parser.send(None)
with open(sys.argv[1]) as file:
for line in file:
for char in line:
parser.send(char)
parser.send(FLUSH) |
t-b
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice addition.
Once that is merged, we can close #366 IMHO.
Two small changes would be nice:
f3fa387 (Add macro for detecting current function name, 2020-07-11)
Can you add a #undef BOOST_CURRENT_FUNCTION so that we don't have that name floating around?
b79d92d (Include current file and line number in log messages, 2020-07-11)
Can you add
#undef TANGO_QUOTE
#undef TANGO_QUOTE_
to the bottom of tango_current_function.h.
It's not that simple. Seems like macros are expanded lazily. See: https://gcc.gnu.org/onlinedocs/cpp/Argument-Prescan.html#Argument-Prescan
#define A 1
#define B A
#undef A
int foo() { return B; }But I think we should remove
|
|
@mliszcz Thanks, learned something today.
Jeep, that is good! |
This is needed to avoid conflicts during compilation of device servers where boost/current_function.hpp is also included.
|
Hi all, |
|
Thanks @sergirubio ! I just added you as a reviewer of this PR. |
|
Hi Michal, I already build your branch and I am going to test it using a modified TangoTest device compiled against it with -v4 flag on it. I have just one question ... to see the information in the DevFailed exception from a client, the client should be also using the same branch or it could be a tango 9.3.4 python client? Sergi |
|
Hi Sergi, If the exception comes from the server, then you don't need the code in this branch on the client side. Location information is just appended to the origin field which is transferred from the server. For exceptions throw from the client code, you'll not have code location information if you use 9.3.4. |
This PR adds code location information to log messages and origin field in DevFailed exception.
Example log message:
Example exception (
Except::print_exceptionoutput):The log message is updated automatically if you use macros like ERROR_STREAM or cout5.
To have exception origin field filled automatically, please use
TANGO_THROW_EXCEPTION(reason, desc)macro (there is also TANGO_RETHROW_EXCEPTION and corresponding macros for _API_EXCEPTION).See also: #564 (comment)