Fix problem with fatal error message

Previous implementation was broken.

Ensure the error file is always written and write its location in the error message
This commit is contained in:
Francesco Abbate 2021-03-05 23:46:41 +01:00
parent 877e4ac6e2
commit 09332fe242
2 changed files with 17 additions and 12 deletions

View File

@ -877,7 +877,7 @@ end
function core.on_error(err)
-- write error to file
local fp = io.open(EXEDIR .. "/error.txt", "wb")
local fp = io.open(USERDIR .. "/error.txt", "wb")
fp:write("Error: " .. tostring(err) .. "\n")
fp:write(debug.traceback(nil, 4))
fp:close()

View File

@ -63,11 +63,11 @@ static void init_window_icon(void) {
#ifdef _WIN32
#define LITE_OS_HOME "USERPROFILE"
#define LITE_PATHSEP_PATTERN "\\\\"
#define LITE_NONPATHSEP_PATTERN "[^\\\\]"
#define LITE_NONPATHSEP_PATTERN "[^\\\\]+"
#else
#define LITE_OS_HOME "HOME"
#define LITE_PATHSEP_PATTERN "/"
#define LITE_NONPATHSEP_PATTERN "[^/]"
#define LITE_NONPATHSEP_PATTERN "[^/]+"
#endif
int main(int argc, char **argv) {
@ -127,23 +127,28 @@ init_lua:
"local core\n"
"xpcall(function()\n"
" HOME = os.getenv('" LITE_OS_HOME "')\n"
" local exedir = EXEFILE:match(\"^(.+)" LITE_PATHSEP_PATTERN LITE_NONPATHSEP_PATTERN "+$\")\n"
" local prefix = exedir:match(\"^(.+)" LITE_PATHSEP_PATTERN "bin$\")\n"
" local exedir = EXEFILE:match(\"^(.*)" LITE_PATHSEP_PATTERN LITE_NONPATHSEP_PATTERN "$\")\n"
" local prefix = exedir:match(\"^(.*)" LITE_PATHSEP_PATTERN "bin$\")\n"
" dofile((prefix and prefix .. '/share/lite-xl' or exedir .. '/data') .. '/core/start.lua')\n"
" core = require('core')\n"
" core.init()\n"
" core.run()\n"
"end, function(err)\n"
" system.show_fatal_error('Lite XL start error', '"
"Fatal error: cannot locate the data directory.\\n"
"Please verify that the data folder is available.')\n"
" local fp = io.open((exedir and exedir .. '/' or '') .. 'error.txt', 'wb')\n"
" fp:write('Error: ' .. tostring(err) .. '\\n')\n"
" fp:write(debug.traceback(nil, 2) .. '\\n')\n"
" fp:close()\n"
" local error_dir\n"
" print('ERROR', err)\n"
" if core and core.on_error then\n"
" error_dir=USERDIR\n"
" pcall(core.on_error, err)\n"
" else\n"
" error_dir=system.absolute_path('.')\n"
" local fp = io.open('error.txt', 'wb')\n"
" fp:write('Error: ' .. tostring(err) .. '\\n')\n"
" fp:write(debug.traceback(nil, 4))\n"
" fp:close()\n"
" end\n"
" system.show_fatal_error('Lite XL internal error',\n"
" 'An internal error occurred in a critical part of the application.\\n\\n'..\n"
" 'Please verify the file \\\"error.txt\\\" in the directory '..error_dir)\n"
" os.exit(1)\n"
"end)\n"
"return core and core.restart_request\n";