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

Re: [PATCH v4 05/11] scalar-diagnose: move functionality to common location

From
Victoria Dye <vdye@github.com>
Date
Aug 12, 2022, 21:00 UTC
Message-ID
<a728c894-4e4a-44c3-a1f5-f87c8bfae13a@github.com>
In-Reply-To
<xmqq7d3db43z.fsf@gitster.g>
Junio C Hamano wrote:
Show 38 quoted lines
> "Victoria Dye via GitGitGadget" <gitgitgadget@gmail.com> writes:
> 
>> +	res = write_archive(archiver_args.nr, (const char **)argv_copy, NULL,
>> +			    the_repository, NULL, 0);
>> +	if (res) {
>> +		error(_("failed to write archive"));
>> +		goto diagnose_cleanup;
>> +	}
>> +
>> +	fprintf(stderr, "\n"
>> +		"Diagnostics complete.\n"
>> +		"All of the gathered info is captured in '%s'\n",
>> +		zip_path->buf);
>> +
>> +diagnose_cleanup:
>> +	if (archiver_fd >= 0) {
>> +		dup2(stdout_fd, STDOUT_FILENO);
>> +		close(stdout_fd);
>> +		close(archiver_fd);
>> +	}
> 
> Hmph, after reading 
> 
> https://lore.kernel.org/git/32f2cadc-556e-1cd5-a238-c8f1cdaaf470@github.com/
> 
> I would have expected to see the above part more like:
> 
>                 res = write_archive(...);
> 
>         diagnose_cleanup:
>                 if (res)
>                         error(...);
>                 else
>                         fprintf(stderr, "Diag complete");
> 
>                 if (archiver_fd >= 0) {
>                         ...
> 

I originally planned to implement it this way, but instead went with adding an error printout explicitly for failed 'add_directory_to_archiver()' calls (in patch 6 [1]). I elaborated on the thought process/reasoning for modifying the approach in the cover letter [2]:

Show 12 quoted lines
> Improved error reporting in 'create_diagnostics_archive()'. I was
> originally going to modify the "failed to write archive" error to trigger
> whenever 'create_diagnostics_archive()' returned a nonzero value.
> However, while working on it I realized the message would no longer be
> tied to a failure of 'write_archive()', making it less helpful in
> pinpointing an issue. To address the original issue
> ('add_directory_to_archiver()' silently failing in
> 'create_diagnostics_archive()'), I instead refactored those calls into a
> loop and added the error message. Now, there's exactly one error message
> printed for each possible early exit scenario from
> 'create_diagnostics_archive()', hopefully avoiding both redundancy &
> under-reporting.

To add a bit more context: when I used the "move 'diagnose_cleanup'" approach, I felt that the added message was either redundant or too general to help a user identify an issue. Redundancy appeared when, for example, 'dup2()' returned a nonzero code; if that happened, we'd get the printouts:

$ git diagnose --suffix test error: could not redirect output: <ERRNO error message> error: could not write archive error: unable to create diagnostics archive 'git-diagnostics-test.zip': <ERRNO error message>

The first two are from 'create_diagnostics_archive()', and the second doesn't really give us information that we don't get out of the third (in 'builtin/diagnose.c').

Conversely, a failure in 'add_directory_to_archiver()' and 'write_archive()' would give us the same printouts (at least within the scope of 'diagnose.c'/'builtin/diagnose.c'):

$ git diagnose --suffix test error: could not write archive error: unable to create diagnostics archive 'git-diagnostics-test.zip: <some error message>

Previously, "could not write archive" would point someone debugging to 'write_archive()'; now, it's unclear.

I ended up settling on adding the error message directly to the 'add_directory_to_archiver()' loop in patch 6 because it meant that:

1. 'create_diagnostics_archive()' would only ever print one error message;
   the others printed would indicate (IMO more clearly) where in the call
   stack the error happened
2. there would be a unique error message for each condition that caused
   'create_diagnostics_archive()' to exit early

Apologies for not sending another reply with these details before re-rolling. I'll be more direct when changing plans in the future.

Thanks!

[1] https://lore.kernel.org/git/710b67e5776363d199ed5043d019386819d44e7e.1660335019.git.gitgitgadget@gmail.com/ [2] https://lore.kernel.org/git/pull.1310.v4.git.1660335019.gitgitgadget@gmail.com/

Previous: Junio C HamanoNext: Junio C Hamano
Message 84 of 94 in “Generalize 'scalar diagnose' into 'git bugreport --diagnose'”
  1. 0/7 Generalize 'scalar diagnose' into 'git bugreport --diagnose'Victoria Dye via GitGitGadget, Aug 1, 2022
  2. 1/7 scalar: use "$GIT_UNZIP" in 'scalar diagnose' testVictoria Dye via GitGitGadget, Aug 1, 2022
  3. Junio C HamanoAug 1, 2022
  4. 2/7 builtin/bugreport.c: create '--diagnose' optionVictoria Dye via GitGitGadget, Aug 1, 2022
  5. Junio C HamanoAug 1, 2022
  6. Victoria DyeAug 2, 2022
  7. Ævar Arnfjörð BjarmasonAug 2, 2022
  8. 3/7 builtin/bugreport.c: avoid size_t overflowVictoria Dye via GitGitGadget, Aug 1, 2022
  9. Junio C HamanoAug 1, 2022
  10. Victoria DyeAug 2, 2022
  11. Junio C HamanoAug 2, 2022
  12. Ævar Arnfjörð BjarmasonAug 2, 2022
  13. Victoria DyeAug 2, 2022
  14. Ævar Arnfjörð BjarmasonAug 3, 2022
  15. 4/7 builtin/bugreport.c: add directory to archiver more gentlyVictoria Dye via GitGitGadget, Aug 1, 2022
  16. Junio C HamanoAug 1, 2022
  17. Victoria DyeAug 2, 2022
  18. 5/7 builtin/bugreport.c: add '--no-report' optionVictoria Dye via GitGitGadget, Aug 1, 2022
  19. Junio C HamanoAug 1, 2022
  20. Victoria DyeAug 2, 2022
  21. 6/7 scalar: use 'git bugreport --diagnose' in 'scalar diagnose'Victoria Dye via GitGitGadget, Aug 1, 2022
  22. 7/7 scalar: update technical doc roadmapVictoria Dye via GitGitGadget, Aug 1, 2022
  23. Junio C HamanoAug 1, 2022
  24. Ævar Arnfjörð BjarmasonAug 2, 2022
  25. Victoria DyeAug 2, 2022
  26. Ævar Arnfjörð BjarmasonAug 3, 2022
  27. 00/10 Generalize 'scalar diagnose' into 'git diagnose' and 'git bugreport --diagnose'Victoria Dye via GitGitGadget, Aug 4, 2022
  28. 01/10 scalar-diagnose: use "$GIT_UNZIP" in testVictoria Dye via GitGitGadget, Aug 4, 2022
  29. 02/10 scalar-diagnose: avoid 32-bit overflow of size_tVictoria Dye via GitGitGadget, Aug 4, 2022
  30. 03/10 scalar-diagnose: add directory to archiver more gentlyVictoria Dye via GitGitGadget, Aug 4, 2022
  31. Ævar Arnfjörð BjarmasonAug 4, 2022
  32. Junio C HamanoAug 4, 2022
  33. Ævar Arnfjörð BjarmasonAug 4, 2022
  34. Junio C HamanoAug 4, 2022
  35. 04/10 scalar-diagnose: move 'get_disk_info()' to 'compat/'Victoria Dye via GitGitGadget, Aug 4, 2022
  36. 06/10 builtin/diagnose.c: create 'git diagnose' builtinVictoria Dye via GitGitGadget, Aug 4, 2022
  37. Ævar Arnfjörð BjarmasonAug 4, 2022
  38. Derrick StoleeAug 5, 2022
  39. Ævar Arnfjörð BjarmasonAug 11, 2022
  40. Derrick StoleeAug 5, 2022
  41. 05/10 scalar-diagnose: move functionality to common locationVictoria Dye via GitGitGadget, Aug 4, 2022
  42. Ævar Arnfjörð BjarmasonAug 4, 2022
  43. 07/10 builtin/diagnose.c: gate certain data behind '--all'Victoria Dye via GitGitGadget, Aug 4, 2022
  44. Ævar Arnfjörð BjarmasonAug 4, 2022
  45. 09/10 scalar-diagnose: use 'git diagnose --all'Victoria Dye via GitGitGadget, Aug 4, 2022
  46. Ævar Arnfjörð BjarmasonAug 4, 2022
  47. Victoria DyeAug 9, 2022
  48. 08/10 builtin/bugreport.c: create '--diagnose' optionVictoria Dye via GitGitGadget, Aug 4, 2022
  49. Derrick StoleeAug 5, 2022
  50. Victoria DyeAug 9, 2022
  51. Derrick StoleeAug 10, 2022
  52. Victoria DyeAug 10, 2022
  53. Derrick StoleeAug 10, 2022
  54. 10/10 scalar: update technical doc roadmapVictoria Dye via GitGitGadget, Aug 4, 2022
  55. Junio C HamanoAug 4, 2022
  56. Victoria DyeAug 9, 2022
  57. Junio C HamanoAug 9, 2022
  58. 00/11 Generalize 'scalar diagnose' into 'git diagnose' and 'git bugreport --diagnose'Victoria Dye via GitGitGadget, Aug 10, 2022
  59. 01/11 scalar-diagnose: use "$GIT_UNZIP" in testVictoria Dye via GitGitGadget, Aug 10, 2022
  60. 02/11 scalar-diagnose: avoid 32-bit overflow of size_tVictoria Dye via GitGitGadget, Aug 10, 2022
  61. 03/11 scalar-diagnose: add directory to archiver more gentlyVictoria Dye via GitGitGadget, Aug 10, 2022
  62. 04/11 scalar-diagnose: move 'get_disk_info()' to 'compat/'Victoria Dye via GitGitGadget, Aug 10, 2022
  63. 05/11 scalar-diagnose: move functionality to common locationVictoria Dye via GitGitGadget, Aug 10, 2022
  64. 07/11 builtin/diagnose.c: create 'git diagnose' builtinVictoria Dye via GitGitGadget, Aug 10, 2022
  65. 06/11 diagnose.c: add option to configure archive contentsVictoria Dye via GitGitGadget, Aug 10, 2022
  66. Junio C HamanoAug 11, 2022
  67. Victoria DyeAug 12, 2022
  68. Ævar Arnfjörð BjarmasonAug 11, 2022
  69. Victoria DyeAug 11, 2022
  70. 09/11 builtin/bugreport.c: create '--diagnose' optionVictoria Dye via GitGitGadget, Aug 10, 2022
  71. Ævar Arnfjörð BjarmasonAug 11, 2022
  72. Victoria DyeAug 11, 2022
  73. Ævar Arnfjörð BjarmasonAug 11, 2022
  74. 08/11 builtin/diagnose.c: add '--mode' optionVictoria Dye via GitGitGadget, Aug 10, 2022
  75. 10/11 scalar-diagnose: use 'git diagnose --mode=all'Victoria Dye via GitGitGadget, Aug 10, 2022
  76. 11/11 scalar: update technical doc roadmapVictoria Dye via GitGitGadget, Aug 10, 2022
  77. 00/11 Generalize 'scalar diagnose' into 'git diagnose' and 'git bugreport --diagnose'Victoria Dye via GitGitGadget, Aug 12, 2022
  78. 01/11 scalar-diagnose: use "$GIT_UNZIP" in testVictoria Dye via GitGitGadget, Aug 12, 2022
  79. 02/11 scalar-diagnose: avoid 32-bit overflow of size_tVictoria Dye via GitGitGadget, Aug 12, 2022
  80. 03/11 scalar-diagnose: add directory to archiver more gentlyVictoria Dye via GitGitGadget, Aug 12, 2022
  81. 04/11 scalar-diagnose: move 'get_disk_info()' to 'compat/'Victoria Dye via GitGitGadget, Aug 12, 2022
  82. 05/11 scalar-diagnose: move functionality to common locationVictoria Dye via GitGitGadget, Aug 12, 2022
  83. Junio C HamanoAug 12, 2022
  84. Victoria DyeAug 12, 2022
  85. Junio C HamanoAug 12, 2022
  86. 06/11 diagnose.c: add option to configure archive contentsVictoria Dye via GitGitGadget, Aug 12, 2022
  87. Junio C HamanoAug 12, 2022
  88. 07/11 builtin/diagnose.c: create 'git diagnose' builtinVictoria Dye via GitGitGadget, Aug 12, 2022
  89. Ævar Arnfjörð BjarmasonAug 18, 2022
  90. Junio C HamanoAug 18, 2022
  91. 09/11 builtin/bugreport.c: create '--diagnose' optionVictoria Dye via GitGitGadget, Aug 12, 2022
  92. 10/11 scalar-diagnose: use 'git diagnose --mode=all'Victoria Dye via GitGitGadget, Aug 12, 2022
  93. 08/11 builtin/diagnose.c: add '--mode' optionVictoria Dye via GitGitGadget, Aug 12, 2022
  94. 11/11 scalar: update technical doc roadmapVictoria Dye via GitGitGadget, Aug 12, 2022

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.