Do you have best practices regarding to which tense to use in message when you’re coding exception-throwing or message-logging code: "Could not acquire connection from DataSource"
versus "Can not acquire connection from DataSource"
?
3
I like to use present tense when the error/exception-generating code is the “root cause” of the problem, and past tense when I’m merely repackaging an error/exception from a lower layer of code.
For example, when our frontend makes a request to our backend, the backend may return an error message “Cannot connect to database”, and the frontend will throw “Failed to retrieve your widgets because: Cannot connect to database”.
In general, the only “best practices” in regards to exception/error wording are to make it as clear, unambiguous, non-misleading and consistent as possible. In my opinion the tense convention I just described fits those criteria the best, but there are probably other equally valid conventions.
I think past tense is a safer bet. In your example:
1) “Could not acquire connection from DataSource” – an attempt was made, failed, situation could’ve changed since then.
2) “Can not acquire connection from DataSource” – an attempt was made, failed, it’s 100% certain that situation is still the same.
Also which tense would you pick for a timeout error?
“Timed out while acquiring connection…”
vs
“Timing out while acquiring connection…”
PS: I would be more worried about including all the helpful details, e.g.: “Could not acquire connection from DataSource ‘[name of server, name of database]’ at [date and time] for user [username].”