From 8a2c67fe70805c99a2b85592ed7f70751a0c323a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E6=99=BA=E8=B6=850668000959?= Date: Mon, 8 Jun 2026 08:52:05 +0800 Subject: [PATCH] fix: check strconv.Atoi and json.Unmarshal errors short_retrieval.go: Check Atoi error even though regex ensures numeric input. gateway.go: Log warning when gateway config JSON is malformed instead of silently using defaults. --- pkg/config/gateway.go | 7 ++++++- pkg/seahorse/short_retrieval.go | 5 ++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pkg/config/gateway.go b/pkg/config/gateway.go index 392a4ca5e..81707273a 100644 --- a/pkg/config/gateway.go +++ b/pkg/config/gateway.go @@ -88,7 +88,12 @@ func ResolveGatewayLogLevel(path string) string { data, err := os.ReadFile(path) if err == nil { - _ = json.Unmarshal(data, &cfg) + if err := json.Unmarshal(data, &cfg); err != nil { + logger.WarnCF("config", "failed to parse gateway config, using defaults", map[string]any{ + "path": path, + "error": err.Error(), + }) + } } if envLevel := os.Getenv("PICOCLAW_LOG_LEVEL"); envLevel != "" { diff --git a/pkg/seahorse/short_retrieval.go b/pkg/seahorse/short_retrieval.go index 3e94eec14..c9f1dd70e 100644 --- a/pkg/seahorse/short_retrieval.go +++ b/pkg/seahorse/short_retrieval.go @@ -22,7 +22,10 @@ func ParseLastDuration(s string) (time.Duration, error) { return 0, fmt.Errorf("invalid duration format: %q (use format like 6h, 7d, 2w, 1m)", s) } - value, _ := strconv.Atoi(matches[1]) + value, err := strconv.Atoi(matches[1]) + if err != nil { + return 0, fmt.Errorf("invalid duration value: %q", matches[1]) + } unit := matches[2] switch unit {