mirror of
https://github.com/status-im/status-desktop.git
synced 2025-02-16 16:47:24 +00:00
fix: prevent recursive logging (#12916)
This commit is contained in:
parent
a18a94f5a9
commit
666c74dcc0
@ -26,34 +26,44 @@ QtObject:
|
|||||||
result.setup()
|
result.setup()
|
||||||
result.events = events
|
result.events = events
|
||||||
|
|
||||||
proc processSignal(self: SignalsManager, statusSignal: string) =
|
# This method might be called with `ChroniclesLogs` event from `nim_status_client`.
|
||||||
|
# In such case we must not log anything to prevent recursive calls.
|
||||||
|
# I tried to make a better solution, but ended up with such workaround, check out PR for more details.
|
||||||
|
proc processSignal(self: SignalsManager, statusSignal: string, allowLogging: bool) =
|
||||||
var jsonSignal: JsonNode
|
var jsonSignal: JsonNode
|
||||||
try:
|
try:
|
||||||
jsonSignal = statusSignal.parseJson
|
jsonSignal = statusSignal.parseJson
|
||||||
except CatchableError:
|
except CatchableError:
|
||||||
error "Invalid signal received", data = statusSignal
|
if allowLogging:
|
||||||
|
error "Invalid signal received", data = statusSignal
|
||||||
return
|
return
|
||||||
|
|
||||||
trace "Raw signal data", data = $jsonSignal
|
if allowLogging:
|
||||||
|
trace "Raw signal data", data = $jsonSignal
|
||||||
|
|
||||||
var signal:Signal
|
var signal:Signal
|
||||||
try:
|
try:
|
||||||
signal = self.decode(jsonSignal)
|
signal = self.decode(jsonSignal)
|
||||||
except CatchableError:
|
except CatchableError:
|
||||||
warn "Error decoding signal", err=getCurrentExceptionMsg()
|
if allowLogging:
|
||||||
|
warn "Error decoding signal", err=getCurrentExceptionMsg()
|
||||||
return
|
return
|
||||||
|
|
||||||
if(signal.signalType == SignalType.NodeLogin):
|
if signal.signalType == SignalType.NodeLogin and NodeSignal(signal).error != "":
|
||||||
if NodeSignal(signal).error != "":
|
if allowLogging:
|
||||||
error "node.login", error=NodeSignal(signal).error
|
error "node.login", error=NodeSignal(signal).error
|
||||||
|
|
||||||
if(signal.signalType == SignalType.NodeCrashed):
|
if signal.signalType == SignalType.NodeCrashed:
|
||||||
|
if allowLogging:
|
||||||
error "node.crashed", error=statusSignal
|
error "node.crashed", error=statusSignal
|
||||||
|
|
||||||
self.events.emit(signal.signalType.event, signal)
|
self.events.emit(signal.signalType.event, signal)
|
||||||
|
|
||||||
proc receiveSignal(self: SignalsManager, signal: string) {.slot.} =
|
proc receiveSignal(self: SignalsManager, signal: string) {.slot.} =
|
||||||
self.processSignal(signal)
|
self.processSignal(signal, allowLogging=true)
|
||||||
|
|
||||||
|
proc receiveChroniclesLogEvent(self: SignalsManager, signal: string) {.slot.} =
|
||||||
|
self.processSignal(signal, allowLogging=false)
|
||||||
|
|
||||||
proc decode(self: SignalsManager, jsonSignal: JsonNode): Signal =
|
proc decode(self: SignalsManager, jsonSignal: JsonNode): Signal =
|
||||||
let signalString = jsonSignal{"type"}.getStr
|
let signalString = jsonSignal{"type"}.getStr
|
||||||
|
@ -51,7 +51,7 @@ proc prepareLogging() =
|
|||||||
proc (logLevel: LogLevel, msg: LogOutputStr) {.gcsafe, raises: [Defect].} =
|
proc (logLevel: LogLevel, msg: LogOutputStr) {.gcsafe, raises: [Defect].} =
|
||||||
try:
|
try:
|
||||||
if signalsManagerQObjPointer != nil:
|
if signalsManagerQObjPointer != nil:
|
||||||
signal_handler(signalsManagerQObjPointer, ($(%* {"type": "chronicles-log", "event": msg})).cstring, "receiveSignal")
|
signal_handler(signalsManagerQObjPointer, ($(%* {"type": "chronicles-log", "event": msg})).cstring, "receiveChroniclesLogEvent")
|
||||||
except:
|
except:
|
||||||
logLoggingFailure(cstring(msg), getCurrentException())
|
logLoggingFailure(cstring(msg), getCurrentException())
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user