Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbfeabcc

Browse files
committed
Add description of error style.
1 parent226bae2 commitbfeabcc

File tree

1 file changed

+299
-0
lines changed

1 file changed

+299
-0
lines changed

‎src/tools/error_text

Lines changed: 299 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,299 @@
1+
To: Peter Eisentraut <peter_e@gmx.net>
2+
cc: pgsql-hackers@postgresql.org
3+
Subject: [HACKERS] Error message style guide, take 2
4+
Date: Wed, 14 May 2003 16:58:18 -0400
5+
From: Tom Lane <tgl@sss.pgh.pa.us>
6+
7+
I'm about to start going through the backend's elog() calls to update
8+
them to ereport() style, add error code numbers, polish wording, etc.
9+
So it's time to nail down our style guide for message wording. Attached
10+
is a revision of the draft that Peter posted on 14-March. Any further
11+
comments?
12+
13+
BTW, I'd like to SGML-ify this and put it into the developer's guide
14+
somewhere; any thoughts where exactly?
15+
16+
regards, tom lane
17+
18+
19+
20+
What goes where
21+
---------------
22+
23+
The primary message should be short, factual, and avoid reference to
24+
implementation details such as specific function names. "Short" means
25+
"should fit on one line under normal conditions". Use a detail message if
26+
needed to keep the primary message short, or if you feel a need to mention
27+
implementation details such as the particular system call that failed.
28+
Both primary and detail messages should be factual. Use a hint message
29+
for suggestions about what to do to fix the problem, especially if the
30+
suggestion might not always be applicable.
31+
32+
For example, instead of
33+
IpcMemoryCreate: shmget(key=%d, size=%u, 0%o) failed: %m
34+
(plus a long addendum that is basically a hint)
35+
write
36+
Primary: Could not create shared memory segment: %m
37+
Detail: Failed syscall was shmget(key=%d, size=%u, 0%o)
38+
Hint: the addendum
39+
40+
RATIONALE: keeping the primary message short helps keep it to the point,
41+
and lets clients lay out screen space on the assumption that one line is
42+
enough for error messages. Detail and hint messages may be relegated to a
43+
verbose mode, or perhaps a pop-up error-details window. Also, details and
44+
hints would normally be suppressed from the server log to save space.
45+
Reference to implementation details is best avoided since users don't know
46+
the details anyway.
47+
48+
49+
Formatting
50+
----------
51+
52+
Don't put any specific assumptions about formatting into the message
53+
texts. Expect clients and the server log to wrap lines to fit their own
54+
needs. In long messages, newline characters (\n) may be used to indicate
55+
suggested paragraph breaks. Don't end a message with a newline. Don't
56+
use tabs or other formatting characters. (In error context displays,
57+
newlines are automatically added to separate levels of context such
58+
as function calls.)
59+
60+
RATIONALE: Messages are not necessarily displayed on terminal-type
61+
displays. In GUI displays or browsers these formatting instructions
62+
are at best ignored.
63+
64+
65+
Quotation marks
66+
---------------
67+
68+
English text should use double quotes when quoting is appropriate.
69+
Text in other languages should consistently use one kind of quotes
70+
that is consistent with publishing customs and computer output of
71+
other programs.
72+
73+
RATIONALE: The choice of double quotes over single quotes is somewhat
74+
arbitrary, but tends to be the preferred use. Some have suggested
75+
choosing the kind of quotes depending on the type of object according to
76+
SQL conventions (namely, strings single quoted, identifiers double
77+
quoted). But this is a language-internal technical issue that many users
78+
aren't even familiar with, it won't scale to other kinds of quoted terms,
79+
it doesn't translate to other languages, and it's pretty pointless, too.
80+
81+
82+
Use of quotes
83+
-------------
84+
85+
Use quotes always to delimit file names, user-supplied identifiers,
86+
and other variables that might contain words. Do not use them to
87+
mark up variables that will not contain words (for example, operator
88+
names).
89+
90+
There are functions in the backend that will double-quote their own
91+
output at need (for example, format_type_be()). Do not put additional
92+
quotes around the output of such functions.
93+
94+
RATIONALE: Objects can have names that create ambiguity when embedded
95+
in a message. Be consistent about denoting where a plugged-in name
96+
starts and ends. But don't clutter messages with unnecessary or
97+
duplicate quote marks.
98+
99+
100+
Grammar and punctuation
101+
-----------------------
102+
103+
The rules are different for primary error messages and for detail/hint
104+
messages:
105+
106+
Primary error messages: Do not capitalize the first letter. Do not end a
107+
message with a period. Do not even think about ending a message with an
108+
exclamation point.
109+
110+
Detail and hint messages: Use complete sentences, and end each with
111+
a period. Capitalize the starts of sentences.
112+
113+
RATIONALE: Avoiding punctuation makes it easier for client applications to
114+
embed the message into a variety of grammatical contexts. Often, primary
115+
messages are not grammatically complete sentences anyway. (And if they're
116+
long enough to be more than one sentence, they should be split into
117+
primary and detail parts.) However, detail and hint messages are longer
118+
and may need to include multiple sentences. For consistency, they should
119+
follow complete-sentence style even when there's only one sentence.
120+
121+
122+
Upper case vs. lower case
123+
-------------------------
124+
125+
Use lower case for message wording, including the first letter of a
126+
primary error message. Use upper case for SQL commands and key words if
127+
they appear in the message.
128+
129+
RATIONALE: It's easier to make everything look more consistent this
130+
way, since some messages are complete sentences and some not.
131+
132+
133+
Avoid passive voice
134+
-------------------
135+
136+
Use the active voice. Use complete sentences when there is an acting
137+
subject ("A could not do B"). Use telegram style without subject if
138+
the subject would be the program itself; do not use "I" for the
139+
program.
140+
141+
RATIONALE: The program is not human. Don't pretend otherwise.
142+
143+
144+
Present vs past tense
145+
---------------------
146+
147+
Use past tense if an attempt to do something failed, but could perhaps
148+
succeed next time (perhaps after fixing some problem). Use present tense
149+
if the failure is certainly permanent.
150+
151+
There is a nontrivial semantic difference between sentences of the
152+
form
153+
154+
could not open file "%s": %m
155+
156+
and
157+
158+
cannot open file "%s"
159+
160+
The first one means that the attempt to open the file failed. The
161+
message should give a reason, such as "disk full" or "file doesn't
162+
exist". The past tense is appropriate because next time the disk
163+
might not be full anymore or the file in question may exist.
164+
165+
The second form indicates the the functionality of opening the named
166+
file does not exist at all in the program, or that it's conceptually
167+
impossible. The present tense is appropriate because the condition
168+
will persist indefinitely.
169+
170+
RATIONALE: Granted, the average user will not be able to draw great
171+
conclusions merely from the tense of the message, but since the
172+
language provides us with a grammar we should use it correctly.
173+
174+
175+
Type of the object
176+
------------------
177+
178+
When citing the name of an object, state what kind of object it is.
179+
180+
RATIONALE: Else no one will know what "foo.bar.baz" is.
181+
182+
183+
Brackets
184+
--------
185+
186+
Square brackets are only to be used (1) in command synopses to denote
187+
optional arguments, or (2) to denote an array subscript.
188+
189+
RATIONALE: Anything else does not correspond to widely-known customary
190+
usage and will confuse people.
191+
192+
193+
Assembling error messages
194+
-------------------------
195+
196+
When a message includes text that is generated elsewhere, embed it in
197+
this style:
198+
199+
could not open file %s: %m
200+
201+
RATIONALE: It would be difficult to account for all possible error codes
202+
to paste this into a single smooth sentence, so some sort of punctuation
203+
is needed. Putting the embedded text in parentheses has also been
204+
suggested, but it's unnatural if the embedded text is likely to be the
205+
most important part of the message, as is often the case.
206+
207+
208+
Reasons for errors
209+
------------------
210+
211+
Messages should always state the reason why an error occurred.
212+
For example:
213+
214+
BAD:could not open file %s
215+
BETTER:could not open file %s (I/O failure)
216+
217+
If no reason is known you better fix the code. ;-)
218+
219+
220+
Function names
221+
--------------
222+
223+
Don't include the name of the reporting routine in the error text.
224+
We have other mechanisms for finding that out when needed, and for
225+
most users it's not helpful information. If the error text doesn't
226+
make as much sense without the function name, reword it.
227+
228+
BAD:pg_atoi: error in "z": can't parse "z"
229+
BETTER:invalid input syntax for integer: "z"
230+
231+
Avoid mentioning called function names, either; instead say what the code
232+
was trying to do:
233+
234+
BAD:open() failed: %m
235+
BETTER:could not open file %s: %m
236+
237+
If it really seems necessary, mention the system call in the detail
238+
message. (In some cases, providing the actual values passed to the
239+
system call might be appropriate information for the detail message.)
240+
241+
RATIONALE: Users don't know what all those functions do.
242+
243+
244+
Tricky words to avoid
245+
---------------------
246+
247+
unable:
248+
249+
"unable" is nearly the passive voice. Better use "cannot" or "could
250+
not", as appropriate.
251+
252+
bad:
253+
254+
Error messages like "bad result" are really hard to interpret
255+
intelligently. It's better to write why the result is "bad", e.g.,
256+
"invalid format".
257+
258+
illegal:
259+
260+
"Illegal" stands for a violation of the law, the rest is "invalid".
261+
Better yet, say why it's invalid.
262+
263+
unknown:
264+
265+
Try to avoid "unknown". Consider "error: unknown response". If you
266+
don't know what the response is, how do you know it's erroneous?
267+
"Unrecognized" is often a better choice. Also, be sure to include the
268+
value being complained of.
269+
270+
BAD:unknown node type
271+
BETTER:unrecognized node type: 42
272+
273+
find vs. exists:
274+
275+
If the program uses a nontrivial algorithm to locate a resource (e.g., a
276+
path search) and that algorithm fails, it is fair to say that the program
277+
couldn't "find" the resource. If, on the other hand, the expected
278+
location of the resource is known but the program cannot access it there
279+
then say that the resource doesn't "exist". Using "find" in this case
280+
sounds weak and confuses the issue.
281+
282+
283+
Proper spelling
284+
---------------
285+
286+
Spell out words in full. For instance, avoid:
287+
288+
spec
289+
stats
290+
parens
291+
auth
292+
xact
293+
294+
RATIONALE: This will improve consistency.
295+
296+
---------------------------(end of broadcast)---------------------------
297+
TIP 3: if posting/reading through Usenet, please send an appropriate
298+
subscribe-nomail command to majordomo@postgresql.org so that your
299+
message can get through to the mailing list cleanly

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp