Use logException consistently and use logDiagnostic

Many places around were re-inventing logException with varying level of success.
In addition, the full error is now printed as a diagnostic instead of debug.
This is more in line with the description of `LogLevel.diagnostic`
("Extended user information (e.g. for more detailed error information)"),
as opposed to the one of `LogLevel.debug_`
("Developer information useful for algorithm debugging").
This commit is contained in:
Geod24 2020-07-24 15:51:40 +09:00 committed by Mathias LANG
parent f3accb40d5
commit bd8c2c6e90
6 changed files with 14 additions and 24 deletions

View file

@ -102,9 +102,8 @@ int runApplication(string[]* args_out = null)
version (VibeDebugCatchAll) { version (VibeDebugCatchAll) {
try { try {
status = runEventLoop(); status = runEventLoop();
} catch( Throwable th ){ } catch (Throwable th) {
logError("Unhandled exception in event loop: %s", th.msg); th.logException("Unhandled exception in event loop");
logDiagnostic("Full exception: %s", th.toString().sanitize());
return 1; return 1;
} }
} else { } else {
@ -908,9 +907,7 @@ Timer setTimer(Duration timeout, void delegate() callback, bool periodic = false
return setTimer(timeout, () @trusted nothrow { return setTimer(timeout, () @trusted nothrow {
try callback(); try callback();
catch (Exception e) { catch (Exception e) {
logWarn("Timer callback failed: %s", e.msg); e.logException!(LogLevel.warn)("Timer callback failed");
scope (failure) assert(false);
logDebug("Full error: %s", e.toString().sanitize);
} }
}, periodic); }, periodic);
} }

View file

@ -211,9 +211,9 @@ void logException(LogLevel level = LogLevel.error)(Throwable exception,
string file = __FILE__, int line = __LINE__) string file = __FILE__, int line = __LINE__)
@safe nothrow { @safe nothrow {
doLog(level, mod, func, file, line, "%s: %s", error_description, exception.msg); doLog(level, mod, func, file, line, "%s: %s", error_description, exception.msg);
try doLog(LogLevel.debug_, mod, func, file, line, try doLog(LogLevel.diagnostic, mod, func, file, line,
"Full exception: %s", () @trusted { return exception.toString(); } ()); "Full exception: %s", () @trusted { return exception.toString(); } ());
catch (Exception e) logDebug("Failed to print full exception: %s", e.msg); catch (Exception e) logDiagnostic("Failed to print full exception: %s", e.msg);
} }
/// ///

View file

@ -143,9 +143,8 @@ TCPListener listenTCP(ushort port, void delegate(TCPConnection) connection_callb
return listenTCP(port, (conn) @trusted nothrow { return listenTCP(port, (conn) @trusted nothrow {
try connection_callback(conn); try connection_callback(conn);
catch (Exception e) { catch (Exception e) {
logError("Handling of connection failed: %s", e.msg); e.logException("Handling of connection failed");
conn.close(); conn.close();
logDebug("Full error: %s", e);
} }
}, address, options); }, address, options);
} }

View file

@ -399,8 +399,8 @@ final package class TaskFiber : Fiber {
debug (VibeTaskLog) logTrace("putting fiber to sleep waiting for new task..."); debug (VibeTaskLog) logTrace("putting fiber to sleep waiting for new task...");
Fiber.yield(); Fiber.yield();
} catch (Exception e) { } catch (Exception e) {
logWarn("CoreTaskFiber was resumed with exception but without active task!"); e.logException!(LogLevel.warn)(
logDiagnostic("Full error: %s", e.toString().sanitize()); "CoreTaskFiber was resumed with exception but without active task");
} }
if (m_shutdown) return; if (m_shutdown) return;
} }
@ -430,9 +430,7 @@ final package class TaskFiber : Fiber {
logDebug("Task exited while an interrupt was in flight."); logDebug("Task exited while an interrupt was in flight.");
} catch (Exception e) { } catch (Exception e) {
debug if (ms_taskEventCallback) ms_taskEventCallback(TaskEvent.fail, handle); debug if (ms_taskEventCallback) ms_taskEventCallback(TaskEvent.fail, handle);
import std.encoding; e.logException!(LogLevel.critical)("Task terminated with uncaught exception");
logCritical("Task terminated with uncaught exception: %s", e.msg);
logDebug("Full error: %s", e.toString().sanitize());
} }
debug assert(Thread.getThis() is m_thread, "Fiber moved?"); debug assert(Thread.getThis() is m_thread, "Fiber moved?");
@ -472,9 +470,8 @@ final package class TaskFiber : Fiber {
// make the fiber available for the next task // make the fiber available for the next task
recycleFiber(this); recycleFiber(this);
} }
} catch(UncaughtException th) { } catch (UncaughtException th) {
logCritical("CoreTaskFiber was terminated unexpectedly: %s", th.msg); th.logException("CoreTaskFiber was terminated unexpectedly");
logDiagnostic("Full error: %s", th.toString().sanitize());
} catch (Throwable th) { } catch (Throwable th) {
import std.stdio : stderr, writeln; import std.stdio : stderr, writeln;
import core.stdc.stdlib : abort; import core.stdc.stdlib : abort;
@ -1016,8 +1013,7 @@ package struct TaskScheduler {
assert(th, "Fiber returned exception object that is not a Throwable!?"); assert(th, "Fiber returned exception object that is not a Throwable!?");
assert(() @trusted nothrow { return t.fiber.state; } () == Fiber.State.TERM); assert(() @trusted nothrow { return t.fiber.state; } () == Fiber.State.TERM);
logError("Task terminated with unhandled exception: %s", th.msg); th.logException("Task terminated with unhandled exception");
logDebug("Full error: %s", () @trusted { return th.toString().sanitize; } ());
// always pass Errors on // always pass Errors on
if (auto err = cast(Error)th) throw err; if (auto err = cast(Error)th) throw err;

View file

@ -349,8 +349,7 @@ private final class WorkerThread : Thread {
handleWorkerTasks(); handleWorkerTasks();
logDebug("Worker thread exit."); logDebug("Worker thread exit.");
} catch (Throwable th) { } catch (Throwable th) {
logFatal("Worker thread terminated due to uncaught error: %s", th.msg); th.logException!(LogLevel.fatal)("Worker thread terminated due to uncaught error");
logDebug("Full error: %s", th.toString().sanitize());
abort(); abort();
} }
} }

View file

@ -112,8 +112,7 @@ int main()
runTask({ runTask({
try runTest(); try runTest();
catch (Throwable th) { catch (Throwable th) {
logError("Test failed: %s", th.msg); th.logException("Test failed");
logDiagnostic("Full error: %s", th);
ret = 1; ret = 1;
} finally exitEventLoop(true); } finally exitEventLoop(true);
}); });