duration: デフォルト値のエラー握り潰し・無音0s・単位不整合を解消 (#17)#23
Merged
Conversation
## 理由 Duration のデフォルト値処理に、(#7)文字列パースエラーの握り潰し、 (#8)未対応型での無音 0s、(#9)単位不整合(int=秒 / time.Duration=ナノ秒) という正確性のフットガンがあった(#17)。設定ミスがサイレントに 0s となり タイムアウト不全等を招くため、可視化しつつ後方互換を保って解消する。 ## 修正点 - 文字列デフォルトのパースエラーを握り潰さず log 出力(panic せず 0s フォールバック) - 未対応型のデフォルトを log 出力(無音 0s をやめる) - int64 / int32 / float64 を「秒」として明示サポート(int と一貫、無音 0s を解消) - env 値のパース失敗も Int* と一貫して log 出力(秘密漏洩回避のためキー名のみ) - 単位規約(int 系=秒、time.Duration=そのまま)を doc コメントと README(en/jp)に明記 - duration_test.go に新挙動(数値型/不正文字列/未対応型)のケースを追加
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.
概要
Durationのデフォルト値処理に集中していた正確性フットガン(#7/#8/#9)を、後方互換を保って解消します。Closes #17
背景(監査検出)
0sを採用(d, _ = time.ParseDuration(s))。Duration("TIMEOUT","30s")のタイポが 0s → ハングやタイトループを招き得るint64/float64等)のデフォルトが全分岐を素通りし無音0s。interface{}シグネチャがコンパイル時チェックを奪うint=秒 だがtime.Duration(60)=60ns(同じ60で 1e9 倍差)変更点(方針: log+0sフォールバック / 単位はドキュメント明記)
log.Printf(panic せず0sフォールバック)(int系の型のparserを増やす #7)log.Printfで警告(無音0sをやめる)(dump dotenv mode #8)int64/int32/float64を「秒」として明示サポート(intと一貫、無音0sを解消)(dump dotenv mode #8)int系=秒、time.Duration=そのまま=ns、string=ParseDuration)を doc コメント + README(en/jp) に明記(Dump dotenv #9)log出力(返り値は不変。秘密漏洩回避のため env 側はキー名のみログ)後方互換
duration_test.goの全ケース(int=秒、time.Duration(60)=60ns 含む)はそのまま通過。挙動の破壊的変更なし(エラー時にログが増えるのみ)テスト
go build/go vet✅、go test/go test -race✅duration_test.goに追加:int64/int32/float64=秒、不正文字列デフォルト→0、未対応型(bool/uint)→0🤖 Generated with Claude Code