Change API for handling Errors
nokome opened this issue · comments
Some suggested API changes after using logga
"for real"...
Change LogInfo.stackTrace
to LogInfo.stack
In this example, I wanted to catch an exception, augment its message with additional information and send the message and the stack trace to the logger:
} catch (error) {
let {message, stack: stackTrace} = error
message = `Processing ${file}: ${message}`
logger.error({message, stackTrace})
}
It would require less thinking and be a little more convenient if you could do:
} catch (error) {
let {message, stack} = error
message = `Processing ${file}: ${message}`
logger.error({message, stack})
}
Add Error
to union type for the message
parameter of logger functions
If Error
was a valid type for the message
parameter i.e.
warning(message: string | LogInfo | Error): void;
Then it would be possible to just pass the error to the function e.g.
} catch (error) {
logger.error(error)
}
Can I suggest something like this: https://docs.python.org/2/library/logging.html#logging.Logger.exception
Which is specifically for logging exceptions. In Python it automatically gets the exception from the current context and logs with ERROR
level. I'm not sure we could do that but could still pass in the error.
} catch (error) {
logger.exception('Error when doing the thing', error)
}
This overloading of argument types doesn't seem good to me.