git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2] CodingGuidelines: a handful of error message guidelines

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 28, 2024, 00:36 UTC
Message-ID
<xmqqa5dkqjmr.fsf_-_@gitster.g>
In-Reply-To
<xmqq1pywvmhq.fsf_-_@gitster.g>

Taking input from comments by Eric (thanks) on the previous round, this iteration adds a bit more about Porcelain/Plumbing and BUG().

  diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines
  index 71e4742fd5..2b8f99f333 100644
  --- a/Documentation/CodingGuidelines
  +++ b/Documentation/CodingGuidelines
  @@ -703,8 +703,15 @@ Error Messages
    - Enclose the subject of an error inside a pair of single quotes,
      e.g. `die(_("unable to open '%s'"), path)`.
   
  - - Unless there is a compelling reason not to, error messages should
  -   be marked for `_("translation")`.
  + - Unless there is a compelling reason not to, error messages from the
  +   Porcelain command should be marked for `_("translation")`.
  +
  + - Error messages from the plumbing commands are sometimes meant for
  +   machine consumption and should not be marked for `_("translation")`
  +   to keep them 'grep'-able.
  +
  + - BUG("message") are for communicating the specific error to
  +   developers, and not to be translated.
   
   
   Externally Visible Names

--- >8 --- It is more efficient to have something in the coding guidelines document to point at, when we want to review and comment on a new message in the codebase to make sure it "fits" in the set of existing messages.

Let's write down established best practice we are aware of.
Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 Documentation/CodingGuidelines | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines
index 3263245b03..2b8f99f333 100644
--- a/Documentation/CodingGuidelines
+++ b/Documentation/CodingGuidelines
@@ -689,16 +689,29 @@ Program Output
 
 Error Messages
 
- - Do not end error messages with a full stop.
+ - Do not end a single-sentence error message with a full stop.
 
  - Do not capitalize the first word, only because it is the first word
-   in the message ("unable to open %s", not "Unable to open %s").  But
+   in the message ("unable to open '%s'", not "Unable to open '%s'").  But
    "SHA-3 not supported" is fine, because the reason the first word is
    capitalized is not because it is at the beginning of the sentence,
    but because the word would be spelled in capital letters even when
    it appeared in the middle of the sentence.
 
- - Say what the error is first ("cannot open %s", not "%s: cannot open")
+ - Say what the error is first ("cannot open '%s'", not "%s: cannot open").
+
+ - Enclose the subject of an error inside a pair of single quotes,
+   e.g. `die(_("unable to open '%s'"), path)`.
+
+ - Unless there is a compelling reason not to, error messages from the
+   Porcelain command should be marked for `_("translation")`.
+
+ - Error messages from the plumbing commands are sometimes meant for
+   machine consumption and should not be marked for `_("translation")`
+   to keep them 'grep'-able.
+
+ - BUG("message") are for communicating the specific error to
+   developers, and not to be translated.
 
 
 Externally Visible Names
-- 
2.47.1-499-g8536fed62d
Previous: Eric SunshineNext: Eric Sunshine
Message 11 of 14 in “fast-import: disallow "." and ".." path components”
  1. fast-import: disallow "." and ".." path componentsElijah Newren via GitGitGadget, Nov 25, 2024
  2. Eric SunshineNov 25, 2024
  3. Elijah NewrenNov 25, 2024
  4. fast-import: disallow "." and ".." path componentsElijah Newren via GitGitGadget, Nov 25, 2024
  5. Patrick SteinhardtNov 26, 2024
  6. Jeff KingNov 27, 2024
  7. Junio C HamanoNov 27, 2024
  8. Kristoffer HaugsbakkNov 27, 2024
  9. Re* [PATCH v2] fast-import: disallow "." and ".." path componentsJunio C Hamano, Nov 27, 2024
  10. Eric SunshineNov 27, 2024
  11. CodingGuidelines: a handful of error message guidelinesJunio C Hamano, Nov 28, 2024
  12. Eric SunshineNov 28, 2024
  13. Junio C HamanoNov 28, 2024
  14. Eric SunshineNov 28, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.