{"record":{"id":"b1ea6acba2b429da","repo":"larksuite/cli","slug":"stat-policy-yaml-q-w","errorCode":null,"errorMessage":"stat policy yaml %q: %w","messagePattern":"stat policy yaml %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cmdpolicy/resolver.go","lineNumber":106,"sourceCode":"\t\t\tseen[pr.PluginName] = true\n\t\t\towners = append(owners, pr.PluginName)\n\t\t}\n\t}\n\treturn owners\n}\n\n// LoadYAMLPolicy returns (nil, nil) when path is empty or file is absent,\n// so callers can pass the result straight into Sources.YAMLRules. A\n// present file yields one or more rules (see yaml.Parse).\nfunc LoadYAMLPolicy(path string) ([]*platform.Rule, error) {\n\tif path == \"\" {\n\t\treturn nil, nil\n\t}\n\tif _, err := vfs.Stat(path); err != nil {\n\t\tif errors.Is(err, os.ErrNotExist) {\n\t\t\treturn nil, nil\n\t\t}\n\t\treturn nil, fmt.Errorf(\"stat policy yaml %q: %w\", path, err)\n\t}\n\tdata, err := vfs.ReadFile(path)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"read policy yaml %q: %w\", path, err)\n\t}\n\trules, err := pyaml.Parse(data)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"policy yaml %q: %w\", path, err)\n\t}\n\treturn rules, nil\n}\n","sourceCodeStart":88,"sourceCodeEnd":118,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/internal/cmdpolicy/resolver.go#L88-L118","documentation":"LoadYAMLPolicy stats the policy YAML to detect existence; a missing file is silently ignored (nil, nil), but any other stat failure is wrapped as 'stat policy yaml %q: %w'. It means the file's existence/properties could not be determined for reasons other than non-existence.","triggerScenarios":"vfs.Stat(path) returns an error that is not os.ErrNotExist — e.g. a path component is not a directory, permission denied on a parent directory, or an I/O error on the underlying filesystem.","commonSituations":"Policy path points inside a directory the process cannot traverse, a symlink loop, a configured policy path whose parent is a regular file, or network/storage backend errors in sandboxed FileIO.","solutions":["Verify each path component of the policy path exists, is a directory, and is traversable","Fix permissions on the parent directories (chmod/chown)","Check the configured policy path for typos that land on a non-directory","If using a sandboxed FileIO, ensure the path is inside the allowed tree"],"exampleFix":"// before\nLoadYAMLPolicy(fio, \"/root/.lark/policy.yaml\") // stat: permission denied\n// after\nLoadYAMLPolicy(fio, filepath.Join(configDir, \"policy.yaml\"))","handlingStrategy":"try-catch","validationCode":"dir := filepath.Dir(policyPath)\nif st, err := os.Stat(dir); err != nil || !st.IsDir() {\n    return fmt.Errorf(\"policy parent dir %s not accessible\", dir)\n}","typeGuard":null,"tryCatchPattern":"rules, err := cmdpolicy.LoadYAMLPolicy(fio, path)\nif err != nil {\n    if strings.Contains(err.Error(), \"stat policy yaml\") {\n        // fix path/permissions; a missing file would NOT error here\n    }\n    return err\n}","preventionTips":["Remember missing files are silently ignored — only stat failures error","Ensure parent directories are traversable by the running user","Avoid symlink loops and paths under read-only/restricted mounts","Resolve the policy path against the FileIO-allowed tree"],"tags":["filesystem","yaml","policy"],"backgroundTag":"file-stat-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"}