fix(date): handle timezone format errors gracefully#113
Merged
Conversation
The date builtin's default format includes %Z (timezone name), which can fail in chrono when the timezone name cannot be determined. Previously, format().to_string() would panic when Display::fmt returned an error. This fix uses write!() to a String instead, which returns a Result, allowing graceful error handling when formatting fails. Changes: - Use std::fmt::Write for safe formatting - Return ExecResult::err() with descriptive message on format failure - Add comprehensive tests for timezone formatting https://claude.ai/code/session_014AiBdrd4m5rkdXRPAVDqta
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
%Ztimezone format fails to determine timezone namestd::fmt::Writefor safe formatting that returns a Result instead of panickingProblem
The date builtin at line 55 used
now.format(format).to_string(), which can panic when chrono'sDisplay::fmtreturns an error. The default format"%a %b %e %H:%M:%S %Z %Y"includes%Z(timezone name), which can fail in environments where timezone information is unavailable or corrupted.Solution
Changed from
format().to_string()(which panics on fmt error) towrite!()which returns aResult, allowing graceful error handling.Test plan
test_date_timezone_utc- verifies UTC timezone formattingtest_date_default_format_includes_timezone- tests default format with %Ztest_date_timezone_local- tests local timezone with graceful error handlingtest_date_combined_format_with_timezone- tests combined format stringstest_date_empty_format- tests edge case with empty formattest_date_literal_text_in_format- tests literal text in format stringscargo clippypasses with no warningscargo fmt --checkpasseshttp_clientfeaturehttps://claude.ai/code/session_014AiBdrd4m5rkdXRPAVDqta