{"record":{"id":"7e6bd8fb1fd3f47a","repo":"larksuite/cli","slug":"marshal-default-config-w","errorCode":null,"errorMessage":"marshal default config: %w","messagePattern":"marshal default config: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"info","filePath":"internal/security/contentsafety/config.go","lineNumber":66,"sourceCode":"\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"compile rule %q pattern: %w\", r.ID, err)\n\t\t}\n\t\trules = append(rules, rule{ID: r.ID, Pattern: compiled})\n\t}\n\treturn &Config{Allowlist: raw.Allowlist, Rules: rules}, nil\n}\n\nfunc EnsureDefaultConfig(configDir string, errOut io.Writer) error {\n\tpath := filepath.Join(configDir, configFileName)\n\tif _, err := vfs.Stat(path); err == nil {\n\t\treturn nil\n\t}\n\tif err := vfs.MkdirAll(configDir, 0700); err != nil {\n\t\treturn fmt.Errorf(\"create config dir: %w\", err)\n\t}\n\tdata, err := json.MarshalIndent(defaultRawConfig(), \"\", \"  \")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"marshal default config: %w\", err)\n\t}\n\tif err := vfs.WriteFile(path, append(data, '\\n'), fs.FileMode(0600)); err != nil {\n\t\treturn err\n\t}\n\tfmt.Fprintf(errOut, \"notice: created default content-safety config at %s\\n\", path)\n\treturn nil\n}\n\nfunc defaultRawConfig() rawConfig {\n\treturn rawConfig{\n\t\tAllowlist: []string{\"all\"},\n\t\tRules: []rawRule{\n\t\t\t{\n\t\t\t\tID:      \"instruction_override\",\n\t\t\t\tPattern: `(?i)ignore\\s+(all\\s+|any\\s+|the\\s+)?(previous|prior|above|earlier)\\s+(instructions?|prompts?|directives?)`,\n\t\t\t},\n\t\t\t{\n\t\t\t\tID:      \"role_injection\",","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/internal/security/contentsafety/config.go#L48-L84","documentation":"EnsureDefaultConfig marshals the built-in default content-safety rules with json.MarshalIndent before writing the default file. This error wraps a marshal failure. Since the default config is a fixed static structure of strings and arrays, this is effectively unreachable and is a defensive guard.","triggerScenarios":"json.MarshalIndent(defaultRawConfig(), \"\", \"  \") returning an error. With the current static defaultRawConfig (plain strings/arrays) this cannot happen; it would only fire if defaults gained unsupported types (channels, funcs, cyclic references).","commonSituations":"Encountered only if the source defaultRawConfig was modified to include unmarshalable values — not reachable in normal use.","solutions":["Inspect the wrapped %w cause to identify the unmarshalable value","Ensure defaultRawConfig returns only JSON-serializable types (strings, slices, maps)","Add a test asserting EnsureDefaultConfig succeeds to catch regressions"],"exampleFix":"// before\nfunc defaultRawConfig() rawConfig { return rawConfig{Rules: []rawRule{{Pattern: badFuncType}}} }\n// after\nfunc defaultRawConfig() rawConfig { return rawConfig{Rules: []rawRule{{ID: \"x\", Pattern: \"y\"}}} }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := contentsafety.EnsureDefaultConfig(dir, os.Stderr); err != nil {\n\tif strings.Contains(err.Error(), \"marshal default config\") {\n\t\t// unreachable with stock defaults; indicates a modified defaultRawConfig\n\t}\n\treturn err\n}","preventionTips":["Keep defaultRawConfig limited to JSON-native types","Add a test asserting EnsureDefaultConfig succeeds","Review changes to defaults for unmarshalable fields"],"tags":["config","json","content-safety"],"backgroundTag":"json-marshal-failed","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}