I am coming back to Nim after a while away and am starting by updating my project from v1.0 to 1.4. I have made a few small changes to my code (like changing strutils.isNilOrWhitespace to isEmptyOrWhitespace) but I'm stuck on another issue.
My project uses the chronicles logging library. When compiling this code (which sets up a destination for my logging messages)
if verbose:
defaultChroniclesStream.outputs[1].writer =
proc (logLevel: LogLevel, msg: LogOutputStr) {.gcsafe.} = ## <--- line 371
stderr.write(msg)
else:
defaultChroniclesStream.outputs[1].writer =
proc (logLevel: LogLevel, msg: LogOutputStr) {.gcsafe.} =
discard
I get the following error from the compiler:
/Users/rory/learn/dancing_links/nim/src/algo_common.nim(371, 7) Error: type mismatch: got <proc (logLevel: LogLevel, msg: LogOutputStr){.gcsafe, locks: 0.}> but expected 'proc (logLevel: LogLevel, logRecord: OutStr){.closure, gcsafe.}'
.raise effects differ
(The error doesn't appear to be due to LogOutputStr vs OutStr, since the chronicles library exports OutStr as LogOuptutStr.)
I've searched for "raise effects differ", but I don't really understand what is going on. The line in the chronicles library that defines this appears to be this one in log_output.nim:
writer*: proc (logLevel: LogLevel, logRecord: OutStr) {.gcsafe, raises: [Defect].}
As as experiment I tried editing this line to add locks: 0 to the pragma list but I still get the same error.
Is the issue actually that the chronicles library specifies raises: [Defect]? If so, what can I do in my code to satisfy the compiler (and why didn't the compiler mention this in the error)?
Or is something else going on?
Yes, that was it. Thanks!
I wish the compiler error had been more helpful, though. ".raise effects differ" is pretty clear, now that I think about it, but the "got X expected Y" message doesn't mention the Defect issue at all and I had to grovel in the library sources to work out what was required.