Server IP : 103.119.228.120 / Your IP : 18.225.149.158 Web Server : Apache System : Linux v8.techscape8.com 3.10.0-1160.119.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Jul 15 12:09:18 UTC 2024 x86_64 User : nobody ( 99) PHP Version : 5.6.40 Disable Function : shell_exec,symlink,system,exec,proc_get_status,proc_nice,proc_terminate,define_syslog_variables,syslog,openlog,closelog,escapeshellcmd,passthru,ocinum cols,ini_alter,leak,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dl,dll,myshellexec,proc_open,socket_bind,proc_close,escapeshellarg,parse_ini_filepopen,fpassthru,exec,passthru,escapeshellarg,escapeshellcmd,proc_close,proc_open,ini_alter,popen,show_source,proc_nice,proc_terminate,proc_get_status,proc_close,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,dl,symlink,shell_exec,system,dl,passthru,escapeshellarg,escapeshellcmd,myshellexec,c99_buff_prepare,c99_sess_put,fpassthru,getdisfunc,fx29exec,fx29exec2,is_windows,disp_freespace,fx29sh_getupdate,fx29_buff_prepare,fx29_sess_put,fx29shexit,fx29fsearch,fx29ftpbrutecheck,fx29sh_tools,fx29sh_about,milw0rm,imagez,sh_name,myshellexec,checkproxyhost,dosyayicek,c99_buff_prepare,c99_sess_put,c99getsource,c99sh_getupdate,c99fsearch,c99shexit,view_perms,posix_getpwuid,posix_getgrgid,posix_kill,parse_perms,parsesort,view_perms_color,set_encoder_input,ls_setcheckboxall,ls_reverse_all,rsg_read,rsg_glob,selfURL,dispsecinfo,unix2DosTime,addFile,system,get_users,view_size,DirFiles,DirFilesWide,DirPrintHTMLHeaders,GetFilesTotal,GetTitles,GetTimeTotal,GetMatchesCount,GetFileMatchesCount,GetResultFiles,fs_copy_dir,fs_copy_obj,fs_move_dir,fs_move_obj,fs_rmdir,SearchText,getmicrotime MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/local/ssl/local/ssl/share/doc/postgresql-9.2.24/html/ |
Upload File : |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >Error Message Style Guide</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REV="MADE" HREF="mailto:pgsql-docs@postgresql.org"><LINK REL="HOME" TITLE="PostgreSQL 9.2.24 Documentation" HREF="index.html"><LINK REL="UP" TITLE="PostgreSQL Coding Conventions" HREF="source.html"><LINK REL="PREVIOUS" TITLE="Reporting Errors Within the Server" HREF="error-message-reporting.html"><LINK REL="NEXT" TITLE="Native Language Support" HREF="nls.html"><LINK REL="STYLESHEET" TYPE="text/css" HREF="stylesheet.css"><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1"><META NAME="creation" CONTENT="2017-11-06T22:43:11"></HEAD ><BODY CLASS="SECT1" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="5" ALIGN="center" VALIGN="bottom" ><A HREF="index.html" >PostgreSQL 9.2.24 Documentation</A ></TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="top" ><A TITLE="Reporting Errors Within the Server" HREF="error-message-reporting.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="10%" ALIGN="left" VALIGN="top" ><A HREF="source.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="60%" ALIGN="center" VALIGN="bottom" >Chapter 47. PostgreSQL Coding Conventions</TD ><TD WIDTH="20%" ALIGN="right" VALIGN="top" ><A TITLE="Native Language Support" HREF="nls.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="SECT1" ><H1 CLASS="SECT1" ><A NAME="ERROR-STYLE-GUIDE" >47.3. Error Message Style Guide</A ></H1 ><P > This style guide is offered in the hope of maintaining a consistent, user-friendly style throughout all the messages generated by <SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN >. </P ><DIV CLASS="SIMPLESECT" ><H2 CLASS="SIMPLESECT" ><A NAME="AEN97647" >47.3.1. What Goes Where</A ></H2 ><P > The primary message should be short, factual, and avoid reference to implementation details such as specific function names. <SPAN CLASS="QUOTE" >"Short"</SPAN > means <SPAN CLASS="QUOTE" >"should fit on one line under normal conditions"</SPAN >. Use a detail message if needed to keep the primary message short, or if you feel a need to mention implementation details such as the particular system call that failed. Both primary and detail messages should be factual. Use a hint message for suggestions about what to do to fix the problem, especially if the suggestion might not always be applicable. </P ><P > For example, instead of: </P><PRE CLASS="PROGRAMLISTING" >IpcMemoryCreate: shmget(key=%d, size=%u, 0%o) failed: %m (plus a long addendum that is basically a hint)</PRE ><P> write: </P><PRE CLASS="PROGRAMLISTING" >Primary: could not create shared memory segment: %m Detail: Failed syscall was shmget(key=%d, size=%u, 0%o). Hint: the addendum</PRE ><P> </P ><P > Rationale: keeping the primary message short helps keep it to the point, and lets clients lay out screen space on the assumption that one line is enough for error messages. Detail and hint messages can be relegated to a verbose mode, or perhaps a pop-up error-details window. Also, details and hints would normally be suppressed from the server log to save space. Reference to implementation details is best avoided since users don't know the details anyway. </P ></DIV ><DIV CLASS="SIMPLESECT" ><H2 CLASS="SIMPLESECT" ><A NAME="AEN97656" >47.3.2. Formatting</A ></H2 ><P > Don't put any specific assumptions about formatting into the message texts. Expect clients and the server log to wrap lines to fit their own needs. In long messages, newline characters (\n) can be used to indicate suggested paragraph breaks. Don't end a message with a newline. Don't use tabs or other formatting characters. (In error context displays, newlines are automatically added to separate levels of context such as function calls.) </P ><P > Rationale: Messages are not necessarily displayed on terminal-type displays. In GUI displays or browsers these formatting instructions are at best ignored. </P ></DIV ><DIV CLASS="SIMPLESECT" ><H2 CLASS="SIMPLESECT" ><A NAME="AEN97660" >47.3.3. Quotation Marks</A ></H2 ><P > English text should use double quotes when quoting is appropriate. Text in other languages should consistently use one kind of quotes that is consistent with publishing customs and computer output of other programs. </P ><P > Rationale: The choice of double quotes over single quotes is somewhat arbitrary, but tends to be the preferred use. Some have suggested choosing the kind of quotes depending on the type of object according to SQL conventions (namely, strings single quoted, identifiers double quoted). But this is a language-internal technical issue that many users aren't even familiar with, it won't scale to other kinds of quoted terms, it doesn't translate to other languages, and it's pretty pointless, too. </P ></DIV ><DIV CLASS="SIMPLESECT" ><H2 CLASS="SIMPLESECT" ><A NAME="AEN97664" >47.3.4. Use of Quotes</A ></H2 ><P > Use quotes always to delimit file names, user-supplied identifiers, and other variables that might contain words. Do not use them to mark up variables that will not contain words (for example, operator names). </P ><P > There are functions in the backend that will double-quote their own output at need (for example, <CODE CLASS="FUNCTION" >format_type_be()</CODE >). Do not put additional quotes around the output of such functions. </P ><P > Rationale: Objects can have names that create ambiguity when embedded in a message. Be consistent about denoting where a plugged-in name starts and ends. But don't clutter messages with unnecessary or duplicate quote marks. </P ></DIV ><DIV CLASS="SIMPLESECT" ><H2 CLASS="SIMPLESECT" ><A NAME="AEN97670" >47.3.5. Grammar and Punctuation</A ></H2 ><P > The rules are different for primary error messages and for detail/hint messages: </P ><P > Primary error messages: Do not capitalize the first letter. Do not end a message with a period. Do not even think about ending a message with an exclamation point. </P ><P > Detail and hint messages: Use complete sentences, and end each with a period. Capitalize the first word of sentences. Put two spaces after the period if another sentence follows (for English text; might be inappropriate in other languages). </P ><P > Error context strings: Do not capitalize the first letter and do not end the string with a period. Context strings should normally not be complete sentences. </P ><P > Rationale: Avoiding punctuation makes it easier for client applications to embed the message into a variety of grammatical contexts. Often, primary messages are not grammatically complete sentences anyway. (And if they're long enough to be more than one sentence, they should be split into primary and detail parts.) However, detail and hint messages are longer and might need to include multiple sentences. For consistency, they should follow complete-sentence style even when there's only one sentence. </P ></DIV ><DIV CLASS="SIMPLESECT" ><H2 CLASS="SIMPLESECT" ><A NAME="AEN97677" >47.3.6. Upper Case vs. Lower Case</A ></H2 ><P > Use lower case for message wording, including the first letter of a primary error message. Use upper case for SQL commands and key words if they appear in the message. </P ><P > Rationale: It's easier to make everything look more consistent this way, since some messages are complete sentences and some not. </P ></DIV ><DIV CLASS="SIMPLESECT" ><H2 CLASS="SIMPLESECT" ><A NAME="AEN97681" >47.3.7. Avoid Passive Voice</A ></H2 ><P > Use the active voice. Use complete sentences when there is an acting subject (<SPAN CLASS="QUOTE" >"A could not do B"</SPAN >). Use telegram style without subject if the subject would be the program itself; do not use <SPAN CLASS="QUOTE" >"I"</SPAN > for the program. </P ><P > Rationale: The program is not human. Don't pretend otherwise. </P ></DIV ><DIV CLASS="SIMPLESECT" ><H2 CLASS="SIMPLESECT" ><A NAME="AEN97687" >47.3.8. Present vs. Past Tense</A ></H2 ><P > Use past tense if an attempt to do something failed, but could perhaps succeed next time (perhaps after fixing some problem). Use present tense if the failure is certainly permanent. </P ><P > There is a nontrivial semantic difference between sentences of the form: </P><PRE CLASS="PROGRAMLISTING" >could not open file "%s": %m</PRE ><P> and: </P><PRE CLASS="PROGRAMLISTING" >cannot open file "%s"</PRE ><P> The first one means that the attempt to open the file failed. The message should give a reason, such as <SPAN CLASS="QUOTE" >"disk full"</SPAN > or <SPAN CLASS="QUOTE" >"file doesn't exist"</SPAN >. The past tense is appropriate because next time the disk might not be full anymore or the file in question might exist. </P ><P > The second form indicates that the functionality of opening the named file does not exist at all in the program, or that it's conceptually impossible. The present tense is appropriate because the condition will persist indefinitely. </P ><P > Rationale: Granted, the average user will not be able to draw great conclusions merely from the tense of the message, but since the language provides us with a grammar we should use it correctly. </P ></DIV ><DIV CLASS="SIMPLESECT" ><H2 CLASS="SIMPLESECT" ><A NAME="AEN97697" >47.3.9. Type of the Object</A ></H2 ><P > When citing the name of an object, state what kind of object it is. </P ><P > Rationale: Otherwise no one will know what <SPAN CLASS="QUOTE" >"foo.bar.baz"</SPAN > refers to. </P ></DIV ><DIV CLASS="SIMPLESECT" ><H2 CLASS="SIMPLESECT" ><A NAME="AEN97702" >47.3.10. Brackets</A ></H2 ><P > Square brackets are only to be used (1) in command synopses to denote optional arguments, or (2) to denote an array subscript. </P ><P > Rationale: Anything else does not correspond to widely-known customary usage and will confuse people. </P ></DIV ><DIV CLASS="SIMPLESECT" ><H2 CLASS="SIMPLESECT" ><A NAME="AEN97706" >47.3.11. Assembling Error Messages</A ></H2 ><P > When a message includes text that is generated elsewhere, embed it in this style: </P><PRE CLASS="PROGRAMLISTING" >could not open file %s: %m</PRE ><P> </P ><P > Rationale: It would be difficult to account for all possible error codes to paste this into a single smooth sentence, so some sort of punctuation is needed. Putting the embedded text in parentheses has also been suggested, but it's unnatural if the embedded text is likely to be the most important part of the message, as is often the case. </P ></DIV ><DIV CLASS="SIMPLESECT" ><H2 CLASS="SIMPLESECT" ><A NAME="AEN97711" >47.3.12. Reasons for Errors</A ></H2 ><P > Messages should always state the reason why an error occurred. For example: </P><PRE CLASS="PROGRAMLISTING" >BAD: could not open file %s BETTER: could not open file %s (I/O failure)</PRE ><P> If no reason is known you better fix the code. </P ></DIV ><DIV CLASS="SIMPLESECT" ><H2 CLASS="SIMPLESECT" ><A NAME="AEN97715" >47.3.13. Function Names</A ></H2 ><P > Don't include the name of the reporting routine in the error text. We have other mechanisms for finding that out when needed, and for most users it's not helpful information. If the error text doesn't make as much sense without the function name, reword it. </P><PRE CLASS="PROGRAMLISTING" >BAD: pg_atoi: error in "z": cannot parse "z" BETTER: invalid input syntax for integer: "z"</PRE ><P> </P ><P > Avoid mentioning called function names, either; instead say what the code was trying to do: </P><PRE CLASS="PROGRAMLISTING" >BAD: open() failed: %m BETTER: could not open file %s: %m</PRE ><P> If it really seems necessary, mention the system call in the detail message. (In some cases, providing the actual values passed to the system call might be appropriate information for the detail message.) </P ><P > Rationale: Users don't know what all those functions do. </P ></DIV ><DIV CLASS="SIMPLESECT" ><H2 CLASS="SIMPLESECT" ><A NAME="AEN97722" >47.3.14. Tricky Words to Avoid</A ></H2 ><DIV CLASS="FORMALPARA" ><P ><B >Unable. </B > <SPAN CLASS="QUOTE" >"Unable"</SPAN > is nearly the passive voice. Better use <SPAN CLASS="QUOTE" >"cannot"</SPAN > or <SPAN CLASS="QUOTE" >"could not"</SPAN >, as appropriate. </P ></DIV ><DIV CLASS="FORMALPARA" ><P ><B >Bad. </B > Error messages like <SPAN CLASS="QUOTE" >"bad result"</SPAN > are really hard to interpret intelligently. It's better to write why the result is <SPAN CLASS="QUOTE" >"bad"</SPAN >, e.g., <SPAN CLASS="QUOTE" >"invalid format"</SPAN >. </P ></DIV ><DIV CLASS="FORMALPARA" ><P ><B >Illegal. </B > <SPAN CLASS="QUOTE" >"Illegal"</SPAN > stands for a violation of the law, the rest is <SPAN CLASS="QUOTE" >"invalid"</SPAN >. Better yet, say why it's invalid. </P ></DIV ><DIV CLASS="FORMALPARA" ><P ><B >Unknown. </B > Try to avoid <SPAN CLASS="QUOTE" >"unknown"</SPAN >. Consider <SPAN CLASS="QUOTE" >"error: unknown response"</SPAN >. If you don't know what the response is, how do you know it's erroneous? <SPAN CLASS="QUOTE" >"Unrecognized"</SPAN > is often a better choice. Also, be sure to include the value being complained of. </P><PRE CLASS="PROGRAMLISTING" >BAD: unknown node type BETTER: unrecognized node type: 42</PRE ><P> </P ></DIV ><DIV CLASS="FORMALPARA" ><P ><B >Find vs. Exists. </B > If the program uses a nontrivial algorithm to locate a resource (e.g., a path search) and that algorithm fails, it is fair to say that the program couldn't <SPAN CLASS="QUOTE" >"find"</SPAN > the resource. If, on the other hand, the expected location of the resource is known but the program cannot access it there then say that the resource doesn't <SPAN CLASS="QUOTE" >"exist"</SPAN >. Using <SPAN CLASS="QUOTE" >"find"</SPAN > in this case sounds weak and confuses the issue. </P ></DIV ><DIV CLASS="FORMALPARA" ><P ><B >May vs. Can vs. Might. </B > <SPAN CLASS="QUOTE" >"May"</SPAN > suggests permission (e.g., "You may borrow my rake."), and has little use in documentation or error messages. <SPAN CLASS="QUOTE" >"Can"</SPAN > suggests ability (e.g., "I can lift that log."), and <SPAN CLASS="QUOTE" >"might"</SPAN > suggests possibility (e.g., "It might rain today."). Using the proper word clarifies meaning and assists translation. </P ></DIV ><DIV CLASS="FORMALPARA" ><P ><B >Contractions. </B > Avoid contractions, like <SPAN CLASS="QUOTE" >"can't"</SPAN >; use <SPAN CLASS="QUOTE" >"cannot"</SPAN > instead. </P ></DIV ></DIV ><DIV CLASS="SIMPLESECT" ><H2 CLASS="SIMPLESECT" ><A NAME="AEN97765" >47.3.15. Proper Spelling</A ></H2 ><P > Spell out words in full. For instance, avoid: <P ></P ></P><UL ><LI ><P > spec </P ></LI ><LI ><P > stats </P ></LI ><LI ><P > parens </P ></LI ><LI ><P > auth </P ></LI ><LI ><P > xact </P ></LI ></UL ><P> </P ><P > Rationale: This will improve consistency. </P ></DIV ><DIV CLASS="SIMPLESECT" ><H2 CLASS="SIMPLESECT" ><A NAME="AEN97780" >47.3.16. Localization</A ></H2 ><P > Keep in mind that error message texts need to be translated into other languages. Follow the guidelines in <A HREF="nls-programmer.html#NLS-GUIDELINES" >Section 48.2.2</A > to avoid making life difficult for translators. </P ></DIV ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="error-message-reporting.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="nls.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Reporting Errors Within the Server</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="source.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Native Language Support</TD ></TR ></TABLE ></DIV ></BODY ></HTML >