Alvaro Herrera <alvhe...@2ndquadrant.com> writes: > This seems to say that we oughta assign GetLastError() to saved_errno > during errstart, then use %m in the errmsg() instead.
No, because in some parts of the code, errno does mean something, even in Windows builds. I think the right fix is to leave %m alone, and instead: (1) save GetLastError's result along with errno during errstart. (2) provide a function, say errlastwinerror(), to be used where elog/ereport calls currently call GetLastError(): elog(ERROR, "something went wrong: error code %lu", errlastwinerror()); What it does, of course, is to reach into the current error stack level and retrieve the saved result. We could use some hack along the line of what Thomas suggested to enforce that this function is used rather than GetLastError(). It's amusing to speculate about whether we could actually cause GetLastError() appearing within elog/ereport to get mapped into this function, thus removing the need to change any code in call sites. But I suspect there's no adequately compiler-independent way to do that. I wonder whether we need to back-patch this. I don't recall seeing any field reports of misleading Windows error codes, but I wonder how many people even look those up ... regards, tom lane