Currently Online

Latest Posts

Topic: Make full load stack visible in FATAL EXCEPTION report

Kontorotsui
Avatar
Topic Opener
Joined: 2021-05-20, 14:35
Posts: 39
Ranking
Pry about Widelands
Posted at: 2023-07-10, 11:57

Hello, I am developing a variant of a tribe (the europeans), and as it can happens, sometimes when I load it I did some mistake, maybe a missing semicolon or comma or a }

The problem is that the FATAL EXCEPTION error shows a lot of useless info like the file /run/build/Widelands/src/scripting/lua_errors.cc:21 that only lists the errors, and instead cuts badly the REAL place where the error happened and makes it harder to find it.

Like this:

[01:56:55.260 real] ERROR:   FATAL EXCEPTION: Error while loading tribe 'europeans': [/run/build/Widelands/src/scripting/lua_errors.cc:21] tribe europeans: Failed adding building 'europeans_farm_medium_basic': [/run/build/Widelands/src/scripting/lua_errors.cc:21] [/run/build/Widelands/src/scripting/lua_errors.cc:21] [/run/build/Widelands/src/scripting/lua_errors.cc:21] [string "addons/europeans_tribe.wad/productionsites_ag..."]:39: '}' expected (to close '{' at line 38) near '.'

As you see the file is cut to "addons/europeans_tribe.wad/productionsites_ag..." and makes it impossible to find it.

I think this is easy to fix, can someone work on it? Should I put it as a bug report? Technically is a feature not a bug.


Top Quote
Nordfriese
Avatar
Joined: 2017-01-17, 17:07
Posts: 1985
OS: Debian Testing
Version: Latest master
Ranking
One Elder of Players
Location: 0x55555d3a34c0
Posted at: 2023-07-10, 19:08

Unfortunately this is not easy at all, since low-level Lua handling is third-party code and not in Widelands itself. So if you want to file a bug report (or want to provide a patch – or someone else wants to provide a patch) it should be reported against the Eris library: https://github.com/fnuecke/eris


Here is the Eris code excerpt (from lobject.c) which at a quick glance seems to assemble the error message:

/* number of chars of a literal string without the ending \0 */
#define LL(x)   (sizeof(x)/sizeof(char) - 1)

#define RETS    "..."
#define PRE "[string \""
#define POS "\"]"

#define addstr(a,b,l)   ( memcpy(a,b,(l) * sizeof(char)), a += (l) )

void luaO_chunkid (char *out, const char *source, size_t bufflen) {
  size_t l = strlen(source);
  if (*source == '=') {  /* 'literal' source */
    if (l <= bufflen)  /* small enough? */
      memcpy(out, source + 1, l * sizeof(char));
    else {  /* truncate it */
      addstr(out, source + 1, bufflen - 1);
      *out = '\0';
    }
  }
  else if (*source == '@') {  /* file name */
    if (l <= bufflen)  /* small enough? */
      memcpy(out, source + 1, l * sizeof(char));
    else {  /* add '...' before rest of name */
      addstr(out, RETS, LL(RETS));
      bufflen -= LL(RETS);
      memcpy(out, source + 1 + l - bufflen, bufflen * sizeof(char));
    }
  }
  else {  /* string; format as [string "source"] */
    const char *nl = strchr(source, '\n');  /* find first new line (if any) */
    addstr(out, PRE, LL(PRE));  /* add prefix */
    bufflen -= LL(PRE RETS POS) + 1;  /* save space for prefix+suffix+'\0' */
    if (l < bufflen && nl == NULL) {  /* small one-line source? */
      addstr(out, source, l);  /* keep it */
    }
    else {
      if (nl != NULL) l = nl - source;  /* stop at first newline */
      if (l > bufflen) l = bufflen;
      addstr(out, source, l);
      addstr(out, RETS, LL(RETS));
    }
    memcpy(out, POS, (LL(POS) + 1) * sizeof(char));
  }
}

Good luck trying to modify that face-wink.png


Top Quote
aDiscoverer
Avatar
Joined: 2022-10-29, 12:23
Posts: 19
Ranking
Pry about Widelands
Posted at: 2023-07-13, 08:44

Work around: run lua your/file.lua (only one file at a time).
Ignore any error about nil values ("index a nil value", "call a nil value") because if it starts to run, then the syntax is OK.

Something like luacheck would be more advanced.

As shell script, to check several files in one go and ignore nil messages:

#!/bin/sh

if [ "$*" = "" ]
then
        set . # default to cur dir
fi

if find "$@" -maxdepth 1 -name '*.lua' -execdir lua -- '{}' ';' 2>&1 |
        grep -v -e 'index a nil value' -e 'call a nil value.*include' |
        grep --colour -A3 '^lua: *[^: ]*'
then # matched error
                return 1 || exit 1
else # no matched error
        # check if any file was checked
        if find "$@" -maxdepth 1 -name '*.lua' -printf _ -quit | grep -q _
        then
                true matched file
        else
                ret=$?
                echo '  no file checked' >&2
                return $ret || exit $ret
        fi
fi

Top Quote
Kontorotsui
Avatar
Topic Opener
Joined: 2021-05-20, 14:35
Posts: 39
Ranking
Pry about Widelands
Posted at: 2023-08-24, 09:14

aDiscoverer wrote:

Work around: run lua your/file.lua (only one file at a time).
Ignore any error about nil values ("index a nil value", "call a nil value") because if it starts to run, then the syntax is OK.

Something like luacheck would be more advanced.

As shell script, to check several files in one go and ignore nil messages:

Great! Thanks!


Top Quote
Kontorotsui
Avatar
Topic Opener
Joined: 2021-05-20, 14:35
Posts: 39
Ranking
Pry about Widelands
Posted at: Today 12:44

Nordfriese wrote:

Unfortunately this is not easy at all, since low-level Lua handling is third-party code and not in Widelands itself. So if you want to file a bug report (or want to provide a patch – or someone else wants to provide a patch) it should be reported against the Eris library: https://github.com/fnuecke/eris


Good luck trying to modify that face-wink.png

Oh... damn. I hoped it was some sort of internal Widelands error output generation, or that at least it was Wideland's code that chose the max length.

Doesn't look easy, I'll post a bug report there, since it will obviously happen elsewhere as well.

Thank you anyway!


Top Quote
Kontorotsui
Avatar
Topic Opener
Joined: 2021-05-20, 14:35
Posts: 39
Ranking
Pry about Widelands
Posted at: Today 12:48

aDiscoverer wrote:

Work around: run lua your/file.lua (only one file at a time).
Ignore any error about nil values ("index a nil value", "call a nil value") because if it starts to run, then the syntax is OK.

Now that is great, but I get this error...

  no file checked
./check_all.sh: line 21: return: can only `return' from a function or sourced script
Edited: Today 12:49

Top Quote
Kontorotsui
Avatar
Topic Opener
Joined: 2021-05-20, 14:35
Posts: 39
Ranking
Pry about Widelands
Posted at: Today 12:57

Also if I try to invoke lua on the single script

lua init.lua

I get this as expected but nothing else

lua: init.lua:1: attempt to call a nil value (global 'push_textdomain')
stack traceback:
        init.lua:1: in main chunk
        [C]: in ?
Edited: Today 12:57

Top Quote