Environment
- CP version: v0.9.4 (
f925e5f6); Go 1.27
Description
cpdaemon/cpm decode the worker config with Go encoding/json. encoding/json matches struct field names case-insensitively (see the json:"..." tags in cpdaemon/pkg/worker/config.go:23-60) and leaves missing fields at their zero value without necessarily failing.
As a result, typos such as snAplen / sNaplen, or omitted required sections, can be silently accepted and the task starts with defaults, which is hard to diagnose.
Steps to reproduce
- Write
snaplen as snAplen.
- It still parses (falls back to the default), with no warning.
Expected
Match field names strictly; report a clear error for missing required fields.
Please confirm
Is this leniency intentional, or can it be tightened?
中文原文
测试环境
- CP 版本:v0.9.4(
f925e5f6);Go 1.27
问题描述
cpdaemon/cpm 用 Go encoding/json 解码 worker 配置。encoding/json 对结构体字段名是大小写不敏感匹配的(见 cpdaemon/pkg/worker/config.go:23-60 的 json:"..." 标签),且缺失字段保留零值、不一定报错。
结果:snAplen / sNaplen 这类拼写错误、漏写必填段,都可能被静默接受并用默认值起 task,排障困难。
重现方法
- 把
snaplen 写成 snAplen;
- 观察仍能解析(落到默认值),无告警。
期望
严格匹配字段名;缺失必填字段给出明确错误。
请确认
这是刻意的宽容,还是可以收紧?
Environment
f925e5f6); Go 1.27Description
cpdaemon/cpmdecode the worker config with Goencoding/json.encoding/jsonmatches struct field names case-insensitively (see thejson:"..."tags incpdaemon/pkg/worker/config.go:23-60) and leaves missing fields at their zero value without necessarily failing.As a result, typos such as
snAplen/sNaplen, or omitted required sections, can be silently accepted and the task starts with defaults, which is hard to diagnose.Steps to reproduce
snaplenassnAplen.Expected
Match field names strictly; report a clear error for missing required fields.
Please confirm
Is this leniency intentional, or can it be tightened?
中文原文
测试环境
f925e5f6);Go 1.27问题描述
cpdaemon/cpm用 Goencoding/json解码 worker 配置。encoding/json对结构体字段名是大小写不敏感匹配的(见cpdaemon/pkg/worker/config.go:23-60的json:"..."标签),且缺失字段保留零值、不一定报错。结果:
snAplen/sNaplen这类拼写错误、漏写必填段,都可能被静默接受并用默认值起 task,排障困难。重现方法
snaplen写成snAplen;期望
严格匹配字段名;缺失必填字段给出明确错误。
请确认
这是刻意的宽容,还是可以收紧?