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

Re: [GSoC PATCH v8 2/2] send-email: finer-grained SMTP error handling

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 25, 2025, 15:34 UTC
Message-ID
<xmqqmsd9m8e6.fsf@gitster.g>
In-Reply-To
<20250324145332.571813-3-05ZYT30@gmail.com>
Zheng Yuting <05zyt30@gmail.com> writes:
> -		# NOTE: SMTP status code handling will be added in a subsequent commit,
> -		# return 1 when failed due to non-credential reasons
> -		return $error ? 1 : ($result ? 1 : 0);
> +		return handle_smtp_error($error, $result);

It was a bit surprising that the new handle-smtp-error sub handles the case without an error. I would actually have expected for it to be something like:

		return ($error
                        ? handle_smtp_error($error)
			: ($result ? 1 : 0));

I.e., we used to unconditionally return 1 upon error, and the only change introduced by this step is to classify $error with the helper function better and behave differently depending on the error.

Having said that ...
Show 5 quoted lines
> +sub handle_smtp_error {
> +	my ($error, $result) = @_;
> +
> +	# If no error is present, return the result directly
> +	return $result ? 1 : 0 unless $error;

... as the "no error" case is implemented as an early return, the mental burden on the readers is not so bad. They can concentrate on the error case when reading the remainder of the function.

Still, it would be with even less mental burden if the no-error case is handled by the caller to make this function only about error cases.

Show 27 quoted lines
> +	# Check if an error was captured
> +	# Parse SMTP status code from error message in:
> +	# https://www.rfc-editor.org/rfc/rfc5321.html
> +	if ($error =~ /\b(\d{3})\b/) {
> +		my $status_code = $1;
> +		if ($status_code =~ /^4/) {
> +			# 4yz: Transient Negative Completion reply
> +			warn "SMTP transient error (status code $status_code): $error";
> +			return 1;
> +		} elsif ($status_code =~ /^5/) {
> +			# 5yz: Permanent Negative Completion reply
> +			warn "SMTP permanent error (status code $status_code): $error";
> +			return 0;
> +		}
> +		# If no recognized status code is found, treat as transient error
> +		warn "SMTP unknown error: $error. Treating as transient failure.";
> +		return 1;
> +	}
> +
> +	# If no status code is found, treat as transient error
> +	warn "SMTP generic error: $error";
> +	return 1;
> +}
> +
>  sub ssl_verify_params {
>  	eval {
>  		require IO::Socket::SSL;
Previous: Zheng YutingNext: Zheng Yuting
Message 24 of 27 in “Refactor SMTP Auth Error Handling”
  1. 0/1 Refactor SMTP Auth Error HandlingZheng Yuting, Mar 12, 2025
  2. 1/1 Unify SMTP auth error handlingZheng Yuting, Mar 12, 2025
  3. Junio C HamanoMar 13, 2025
  4. Yuting ZhengMar 14, 2025
  5. 0/2 smtp_auth_maybe: unified error capture and status code processing optimizationZheng Yuting, Mar 16, 2025
  6. 1/2 Unify capture of SMTP errorsZheng Yuting, Mar 16, 2025
  7. 2/2 Error handling for SMTP status codesZheng Yuting, Mar 16, 2025
  8. Junio C HamanoMar 17, 2025
  9. 0/2 sendemail: improve error capture and status code handlingZheng Yuting, Mar 19, 2025
  10. 1/2 sendemail: capture errors in an eval {} blockZheng Yuting, Mar 19, 2025
  11. 2/2 sendemail: finer-grained SMTP error handlingZheng Yuting, Mar 19, 2025
  12. Meet SoniMar 19, 2025
  13. 0/2 send-email: improve error capture and status code handlingZheng Yuting, Mar 21, 2025
  14. 1/2 send-email: capture errors in an eval {} blockZheng Yuting, Mar 21, 2025
  15. 2/2 send-email: finer-grained SMTP error handlingZheng Yuting, Mar 21, 2025
  16. Junio C HamanoMar 21, 2025
  17. 0/2 send-email: improve error capture and status code handlingZheng Yuting, Mar 23, 2025
  18. 1/2 send-email: capture errors in an eval {} blockZheng Yuting, Mar 23, 2025
  19. 2/2 send-email: finer-grained SMTP error handlingZheng Yuting, Mar 23, 2025
  20. Junio C HamanoMar 24, 2025
  21. 0/2 send-email: improve error capture and status code handlingZheng Yuting, Mar 24, 2025
  22. 1/2 send-email: capture errors in an eval {} blockZheng Yuting, Mar 24, 2025
  23. 2/2 send-email: finer-grained SMTP error handlingZheng Yuting, Mar 24, 2025
  24. Junio C HamanoMar 25, 2025
  25. 0/2 send-email: improve error capture and status code handlingZheng Yuting, Mar 26, 2025
  26. 1/2 send-email: capture errors in an eval {} blockZheng Yuting, Mar 26, 2025
  27. 2/2 send-email: finer-grained SMTP error handlingZheng Yuting, Mar 26, 2025

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.