Skip to content

Commit

Permalink
Use logException consistently and use logDiagnostic
Browse files Browse the repository at this point in the history
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").
  • Loading branch information
Geod24 committed Aug 24, 2020
1 parent f3accb4 commit bd8c2c6
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 24 deletions.
9 changes: 3 additions & 6 deletions source/vibe/core/core.d
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions source/vibe/core/log.d
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

///
Expand Down
3 changes: 1 addition & 2 deletions source/vibe/core/net.d
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
16 changes: 6 additions & 10 deletions source/vibe/core/task.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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?");
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions source/vibe/core/taskpool.d
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
3 changes: 1 addition & 2 deletions tests/0-tcpproxy.d
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down

0 comments on commit bd8c2c6

Please sign in to comment.