BehaviorTree / Groot2

36 stars 0 forks source link

Show useful error message on invalid XML instead of crash #40

Open Roboterbastler opened 7 months ago

Roboterbastler commented 7 months ago

Is your feature request related to a problem? Please describe. I came across this problem when I accidentally had an invalid name="..." attribute in some of the SubTree XML tags, e.g. like this:

<SubTree ID="MySubTree"
         name="MySubTree"
         some_remap="{some_remap}" />

According to the docs the SubTree tag does not take a name attribute, so this XML was invalid and name probably interpreted as a port. While the behavior tree would run without any complaint, when trying to connect Groot2 monitoring then Groot2 just crashes without any meaningful message. It took me quite a while to find the cause of this.

When removing the name attributes the same tree can be monitored with Groot2.

Describe the solution you'd like Instead of a cryptic crash it would be nice if an error message informed me that the XML is invalid, ideally point me roughly to the place where it is invalid.

Additional context The stack trace of the crash is the following:

version: 1.5.1
Stack trace (most recent call last):
#0  | Source "/usr/include/c++/9/bits/std_function.h", line 300, in _M_invoke
    |   299:       {
    | > 300:    (*_Base::_M_get_pointer(__functor))(
    |   301:        std::forward<_ArgTypes>(__args)...);
    | Source "/media/davide/DATA/ws_behavior/src/Groot2/src_gui/monitor/monitor_mode.cpp", line 500, in operator()
      Source "/home/davide/QtDev/6.5.2/gcc_64/include/QtCore/qstring.h", line 1552, in QString::fromStdString(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) [0x56413fe9ffd6]
#1  | Source "/media/davide/DATA/ws_behavior/src/Groot2/src_gui/monitor/monitor_mode.cpp", line 507, in MonitorMode::addTreeItems(QString const&, QMap<QString, std::shared_ptr<groot::TreeInstance> > const&)
      Source "/usr/include/c++/9/bits/std_function.h", line 688, in std::function<void (QString)>::operator()(QString) const [0x56413ffaff14]
        687:    __throw_bad_function_call();
      > 688:       return _M_invoker(_M_functor, std::forward<_ArgTypes>(__args)...);
        689:     }
#2    Source "/media/davide/DATA/ws_behavior/src/Groot2/src_gui/monitor/monitor_mode.cpp", line 429, in MonitorMode::loadZMQTree(QByteArray const&) [0x56413ffb3300]
#3  | Source "/home/davide/QtDev/6.5.2/gcc_64/include/QtCore/qobjectdefs_impl.h", line 409, in impl
    | Source "/home/davide/QtDev/6.5.2/gcc_64/include/QtCore/qobjectdefs_impl.h", line 241, in call<QtPrivate::List<>, void>
    | Source "/home/davide/QtDev/6.5.2/gcc_64/include/QtCore/qobjectdefs_impl.h", line 127, in call
      Source "/media/davide/DATA/ws_behavior/src/Groot2/src_gui/monitor/monitor_mode.cpp", line 147, in operator() [0x56413ffb367b]
#4    Object "/tmp/.mount_Groot2LPp30z/usr/bin/../lib/libQt6Core.so.6", at 0x7f6f71135f9b, in QObject::event(QEvent*)
#5    Object "/tmp/.mount_Groot2LPp30z/usr/bin/../lib/libQt6Widgets.so.6", at 0x7f6f723a2ff1, in QApplicationPrivate::notify_helper(QObject*, QEvent*)
#6    Object "/tmp/.mount_Groot2LPp30z/usr/bin/../lib/libQt6Core.so.6", at 0x7f6f710e69e9, in QCoreApplication::notifyInternal2(QObject*, QEvent*)
#7    Object "/tmp/.mount_Groot2LPp30z/usr/bin/../lib/libQt6Core.so.6", at 0x7f6f710e9c0c, in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*)
#8    Object "/tmp/.mount_Groot2LPp30z/usr/bin/../lib/libQt6Core.so.6", at 0x7f6f71391df2, in QEventDispatcherGlibPrivate::runTimersOnceWithNormalPriority()
#9    Object "/tmp/.mount_Groot2LPp30z/usr/bin/../lib/libglib-2.0.so.0", at 0x7f6f7063317c, in g_main_context_dispatch
#10   Object "/tmp/.mount_Groot2LPp30z/usr/bin/../lib/libglib-2.0.so.0", at 0x7f6f706333ff, in g_main_context_dispatch
#11   Object "/tmp/.mount_Groot2LPp30z/usr/bin/../lib/libglib-2.0.so.0", at 0x7f6f706334a2, in g_main_context_iteration
#12   Object "/tmp/.mount_Groot2LPp30z/usr/bin/../lib/libQt6Core.so.6", at 0x7f6f71391779, in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>)
#13   Object "/tmp/.mount_Groot2LPp30z/usr/bin/../lib/libQt6Core.so.6", at 0x7f6f710f22ea, in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>)
#14   Object "/tmp/.mount_Groot2LPp30z/usr/bin/../lib/libQt6Core.so.6", at 0x7f6f710eeb1d, in QCoreApplication::exec()
#15   Source "/media/davide/DATA/ws_behavior/src/Groot2/src_gui/main.cpp", line 190, in main [0x56413feb06ed]
-----------------------------
facontidavide commented 7 months ago

Hi,

thanks a lot for figuring this out. I will fix it as soon as possible!