A string is read by someone in the middle of a task, so decide who reads it before rewording it.
- A person who uses the program knows their task and their data but not the program's internals.
Name things in their words, never a module, a type or a step of the implementation.
- A maintainer who reads a panic, a log line or an internal check knows the code.
An internal name is fine for them, but the message still says what went wrong.
Then make it as short as it can be while it stays clear:
- State the problem or the state in one short clause, and start with its subject.
- Give a fix after the problem only where the fix is not obvious and has one form.
- Do not explain the message in a trailing clause, or narrate what the program or an input would do.
A synonym that keeps the shape of a hit does not fix it. Rewrite the string from what its reader needs to know.