Hello, all
Could you give me your opinions on the message style? Recently, I got different comments from Magnus and Alvaro during
thereview of "Supporting huge_pages on Windows", which is now shifted to CommitFest 2017-3. To be more specific, I'm
modifyingsrc/backend/port/win32_shmem.c b/src/backend/port/win32_shmem.c. This file has existing messages like this:
[Existing message] ereport(FATAL, (errmsg("could not create shared memory segment: error code %lu",
GetLastError()), errdetail("Failed system call was CreateFileMapping(size=%zu, name=%s).", size,
szShareMem)));
I added a few ereport() calls that emit the same message except for the Win32 API name. Which of the following do you
thinkis the best? I'd like to follow the majority.
[Option 1] ereport(elevel, (errmsg("could not enable Lock pages in memory user right"), errdetail("Failed
systemcall was %s, error code %lu", "OpenProcessToken", GetLastError())));
[Option 2] ereport(elevel, (errmsg("could not enable Lock Pages in Memory user right: error code %lu",
GetLastError()), errdetail("Failed system call was OpenProcessToken.")));
Alvaro thinks that Option 1 is better because it eliminates redundant translation work. Magnus says Option 2 is better
becauseit matches the style of existing messages in the same file.
[Magnus's comment]
this seems to be a new pattern of code -- for other similar cases it
just writes LookupPrivilegeValue inside the patch itself. I'm guessing
the idea was for translatability, but I think it's better we stick to
the existing pattern.
[Alvaro's comment]
There are two reasons for doing things this way. One is that you reduce the chances of a translator making a mistake
withthe function name (say just a typo, or in egregious cases they may even translate the function name). The other is
thatif you have many of these messages, you only translate the generic part once instead of having the same message a
handfulof times, exactly identical but for the function name.
So please do apply that kind of pattern wherever possible. We already have the proposed error message, twice. No need
fortwo more occurrences of it.
I'm rather inclined to choose Option 1 to reduce message translation work. Actually, is the Option 3 the best so that
italigns with the existing messages by putting the error code in the primary message?
[Option 3] ereport(elevel, (errmsg("could not enable Lock pages in memory user right: error code %lu",
GetLastError()), errdetail("Failed system call was %s", "OpenProcessToken")));
Regards
Takayuki Tsunakawa