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:
parent
f3accb40d5
commit
bd8c2c6e90
|
@ -102,9 +102,8 @@ int runApplication(string[]* args_out = null)
|
|||
version (VibeDebugCatchAll) {
|
||||
try {
|
||||
status = runEventLoop();
|
||||
} catch( Throwable th ){
|
||||
logError("Unhandled exception in event loop: %s", th.msg);
|
||||
logDiagnostic("Full exception: %s", th.toString().sanitize());
|
||||
} catch (Throwable th) {
|
||||
th.logException("Unhandled exception in event loop");
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
|
@ -908,9 +907,7 @@ Timer setTimer(Duration timeout, void delegate() callback, bool periodic = false
|
|||
return setTimer(timeout, () @trusted nothrow {
|
||||
try callback();
|
||||
catch (Exception e) {
|
||||
logWarn("Timer callback failed: %s", e.msg);
|
||||
scope (failure) assert(false);
|
||||
logDebug("Full error: %s", e.toString().sanitize);
|
||||
e.logException!(LogLevel.warn)("Timer callback failed");
|
||||
}
|
||||
}, periodic);
|
||||
}
|
||||
|
|
|
@ -211,9 +211,9 @@ void logException(LogLevel level = LogLevel.error)(Throwable exception,
|
|||
string file = __FILE__, int line = __LINE__)
|
||||
@safe nothrow {
|
||||
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(); } ());
|
||||
catch (Exception e) logDebug("Failed to print full exception: %s", e.msg);
|
||||
catch (Exception e) logDiagnostic("Failed to print full exception: %s", e.msg);
|
||||
}
|
||||
|
||||
///
|
||||
|
|
|
@ -143,9 +143,8 @@ TCPListener listenTCP(ushort port, void delegate(TCPConnection) connection_callb
|
|||
return listenTCP(port, (conn) @trusted nothrow {
|
||||
try connection_callback(conn);
|
||||
catch (Exception e) {
|
||||
logError("Handling of connection failed: %s", e.msg);
|
||||
e.logException("Handling of connection failed");
|
||||
conn.close();
|
||||
logDebug("Full error: %s", e);
|
||||
}
|
||||
}, address, options);
|
||||
}
|
||||
|
|
|
@ -399,8 +399,8 @@ final package class TaskFiber : Fiber {
|
|||
debug (VibeTaskLog) logTrace("putting fiber to sleep waiting for new task...");
|
||||
Fiber.yield();
|
||||
} catch (Exception e) {
|
||||
logWarn("CoreTaskFiber was resumed with exception but without active task!");
|
||||
logDiagnostic("Full error: %s", e.toString().sanitize());
|
||||
e.logException!(LogLevel.warn)(
|
||||
"CoreTaskFiber was resumed with exception but without active task");
|
||||
}
|
||||
if (m_shutdown) return;
|
||||
}
|
||||
|
@ -430,9 +430,7 @@ final package class TaskFiber : Fiber {
|
|||
logDebug("Task exited while an interrupt was in flight.");
|
||||
} catch (Exception e) {
|
||||
debug if (ms_taskEventCallback) ms_taskEventCallback(TaskEvent.fail, handle);
|
||||
import std.encoding;
|
||||
logCritical("Task terminated with uncaught exception: %s", e.msg);
|
||||
logDebug("Full error: %s", e.toString().sanitize());
|
||||
e.logException!(LogLevel.critical)("Task terminated with uncaught exception");
|
||||
}
|
||||
|
||||
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
|
||||
recycleFiber(this);
|
||||
}
|
||||
} catch(UncaughtException th) {
|
||||
logCritical("CoreTaskFiber was terminated unexpectedly: %s", th.msg);
|
||||
logDiagnostic("Full error: %s", th.toString().sanitize());
|
||||
} catch (UncaughtException th) {
|
||||
th.logException("CoreTaskFiber was terminated unexpectedly");
|
||||
} catch (Throwable th) {
|
||||
import std.stdio : stderr, writeln;
|
||||
import core.stdc.stdlib : abort;
|
||||
|
@ -1016,8 +1013,7 @@ package struct TaskScheduler {
|
|||
assert(th, "Fiber returned exception object that is not a Throwable!?");
|
||||
|
||||
assert(() @trusted nothrow { return t.fiber.state; } () == Fiber.State.TERM);
|
||||
logError("Task terminated with unhandled exception: %s", th.msg);
|
||||
logDebug("Full error: %s", () @trusted { return th.toString().sanitize; } ());
|
||||
th.logException("Task terminated with unhandled exception");
|
||||
|
||||
// always pass Errors on
|
||||
if (auto err = cast(Error)th) throw err;
|
||||
|
|
|
@ -349,8 +349,7 @@ private final class WorkerThread : Thread {
|
|||
handleWorkerTasks();
|
||||
logDebug("Worker thread exit.");
|
||||
} catch (Throwable th) {
|
||||
logFatal("Worker thread terminated due to uncaught error: %s", th.msg);
|
||||
logDebug("Full error: %s", th.toString().sanitize());
|
||||
th.logException!(LogLevel.fatal)("Worker thread terminated due to uncaught error");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -112,8 +112,7 @@ int main()
|
|||
runTask({
|
||||
try runTest();
|
||||
catch (Throwable th) {
|
||||
logError("Test failed: %s", th.msg);
|
||||
logDiagnostic("Full error: %s", th);
|
||||
th.logException("Test failed");
|
||||
ret = 1;
|
||||
} finally exitEventLoop(true);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue