parse: パースエラーログに生のenv値を出力しない (#20)#25
Merged
Merged
Conversation
## 理由 Int* はパースエラー時に生の env 値を log 出力していた(#20)。加えて、 strconv / time.ParseDuration のエラーメッセージ自体が入力値を埋め込むため、 単に "%v err" を出すだけでは依然として生値が漏れる。Duration の env パース 失敗ログ(#17 で追加)も同じ理由で生値を漏らしていた。数値想定の変数に機微値が 誤設定された場合に、その値がログに残るのを防ぐ。 ## 修正点 - Int / Int32 / Int64 / Int16: strconv.NumError から値を含まない理由のみ (invalid syntax / value out of range)を抽出する parseErrReason を導入し、 生値・生エラーを出力しないように変更(#20) - Duration(env 側): time エラーは値なし理由を構造的に取得できないため、 キー名のみをログ出力するよう変更 - int_test.go を追加(全 Int 系で生値非出力・キー出力・理由出力を検証) - duration_test.go に生値非出力の回帰テストを追加し gofmt 整形
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.
概要
パースエラー時のログに、生の環境変数値が漏れないよう修正します。
Closes #20
背景と落とし穴
Int*はパースエラー時に生の env 値をlog.Printf("parse error: input: %v, ...", v, ...)で出力していました(#20)。ただし issue #20 が提案していた素朴な修正
log.Printf("...%q as int: %v", key, err)は不十分です。strconv/time.ParseDurationのエラーメッセージ自体が入力値を埋め込むため(例:strconv.ParseInt: parsing "<生値>": invalid syntax)、%v errでそのまま漏れます。同じ理由で、#17 で Duration に追加した env パース失敗ログ(
time: invalid duration "<生値>")も生値を漏らしていました。本 PR で両方まとめて潰します。変更点
strconv.NumErrorから値を含まない理由のみ(invalid syntax/value out of range)を抽出するparseErrReasonを導入。生値も生エラー文字列も出力しない(Int*: パースエラー時に生のenv値をログ出力しない #20)getenv: failed to parse "PORT" as int: invalid syntax(生値なし、理由は保持)timeエラーは値なし理由を構造的に取得できないため、キー名のみログ出力getenv: failed to parse value for "TIMEOUT" as durationテスト
int_test.go新規: 全 Int 系で「生値が出ない / キーが出る / 理由(invalid syntax)が出る / デフォルトにフォールバック」を検証(この回帰テストは素朴な修正なら失敗します)duration_test.go: env パース失敗で生値が出ないことを検証 + gofmt 整形go build/go vet/go test/go test -raceすべて ✅🤖 Generated with Claude Code