Show error message in crash message box (#1461)

* Save to `error.txt` the same traceback shown on stdout
* Show error message in crash message box
This commit is contained in:
Guldoman 2023-04-14 21:22:22 +02:00 committed by George Sokianos
parent 6ad288aa39
commit 0be18493a9
1 changed files with 7 additions and 6 deletions

View File

@ -237,22 +237,23 @@ init_lua:
" core.init()\n" " core.init()\n"
" core.run()\n" " core.run()\n"
"end, function(err)\n" "end, function(err)\n"
" local error_dir\n" " local error_path = 'error.txt'\n"
" io.stdout:write('Error: '..tostring(err)..'\\n')\n" " io.stdout:write('Error: '..tostring(err)..'\\n')\n"
" io.stdout:write(debug.traceback(nil, 2)..'\\n')\n" " io.stdout:write(debug.traceback(nil, 2)..'\\n')\n"
" if core and core.on_error then\n" " if core and core.on_error then\n"
" error_dir=USERDIR\n" " error_path = USERDIR .. PATHSEP .. error_path\n"
" pcall(core.on_error, err)\n" " pcall(core.on_error, err)\n"
" else\n" " else\n"
" error_dir=system.absolute_path('.')\n" " local fp = io.open(error_path, 'wb')\n"
" local fp = io.open('error.txt', 'wb')\n"
" fp:write('Error: ' .. tostring(err) .. '\\n')\n" " fp:write('Error: ' .. tostring(err) .. '\\n')\n"
" fp:write(debug.traceback(nil, 4)..'\\n')\n" " fp:write(debug.traceback(nil, 2)..'\\n')\n"
" fp:close()\n" " fp:close()\n"
" error_path = system.absolute_path(error_path)\n"
" end\n" " end\n"
" system.show_fatal_error('Lite XL internal error',\n" " system.show_fatal_error('Lite XL internal error',\n"
" 'An internal error occurred in a critical part of the application.\\n\\n'..\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" " 'Error: '..tostring(err)..'\\n\\n'..\n"
" 'Details can be found in \\\"'..error_path..'\\\"')\n"
" os.exit(1)\n" " os.exit(1)\n"
"end)\n" "end)\n"
"return core and core.restart_request\n"; "return core and core.restart_request\n";