{"record":{"id":"34498047492464aa","repo":"larksuite/cli","slug":"create-config-dir-w","errorCode":null,"errorMessage":"create config dir: %w","messagePattern":"create config dir: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/security/contentsafety/config.go","lineNumber":62,"sourceCode":"\t}\n\trules := make([]rule, 0, len(raw.Rules))\n\tfor _, r := range raw.Rules {\n\t\tcompiled, err := regexp.Compile(r.Pattern)\n\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\",","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/internal/security/contentsafety/config.go#L44-L80","documentation":"EnsureDefaultConfig creates the config directory (via vfs.MkdirAll, mode 0700) before writing the default content-safety config file. This error wraps a failure to create that directory — e.g. a file exists at that path, or permission is denied on the parent.","triggerScenarios":"Calling EnsureDefaultConfig(configDir, errOut) (directly or via loadOrCreate) when configDir exists as a regular file, or a parent directory blocks creation with EACCES/EPERM.","commonSituations":"LARKSUITE_CLI_CONFIG_DIR accidentally set to a file path; read-only home or container filesystem; a stale file where the config directory should be.","solutions":["Check whether configDir exists as a file and remove/rename it","Fix permissions on the parent directory so the process can create the directory","Point LARKSUITE_CLI_CONFIG_DIR at a writable directory","Inspect the wrapped %w cause (syscall) for the exact OS-level reason"],"exampleFix":"// before\nexport LARKSUITE_CLI_CONFIG_DIR=/home/me/config-file.txt  // it's a file\n// after\nrm /home/me/config-file.txt\nexport LARKSUITE_CLI_CONFIG_DIR=/home/me/.config/lark-cli","handlingStrategy":"validation","validationCode":"if info, err := os.Stat(configDir); err == nil && !info.IsDir() {\n\treturn fmt.Errorf(\"%s exists and is not a directory\", configDir)\n}\nif err := os.MkdirAll(configDir, 0o700); err != nil {\n\treturn fmt.Errorf(\"cannot create config dir: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := contentsafety.EnsureDefaultConfig(dir, os.Stderr); err != nil {\n\tif strings.Contains(err.Error(), \"create config dir\") && errors.Is(err, os.ErrPermission) {\n\t\t// pick a writable dir or fix parent permissions\n\t}\n\treturn err\n}","preventionTips":["Ensure LARKSUITE_CLI_CONFIG_DIR points to a directory, never a file","Provision config dirs with mode 0700 in setup scripts","Avoid read-only filesystems for config storage","Check disk space and parent-directory write access"],"tags":["config","filesystem","permissions","content-safety"],"backgroundTag":"mkdir-permission-denied","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"}