{"record":{"id":"88b96da5e02fe028","repo":"larksuite/cli","slug":"read-policy-yaml-q-w","errorCode":null,"errorMessage":"read policy yaml %q: %w","messagePattern":"read policy yaml %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cmdpolicy/resolver.go","lineNumber":110,"sourceCode":"\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":92,"sourceCodeEnd":118,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/internal/cmdpolicy/resolver.go#L92-L118","documentation":"After confirming the policy YAML exists via Stat, LoadYAMLPolicy reads it with vfs.ReadFile; any read failure is wrapped as 'read policy yaml %q: %w'. This is distinct from stat errors and parse errors — the file exists but its content could not be read.","triggerScenarios":"vfs.ReadFile fails on an existing policy file: permission denied on the file itself, it is a directory named policy.yaml, an I/O error, or the file was deleted between Stat and Read (TOCTOU).","commonSituations":"Policy file with restrictive permissions (e.g. owned by another user), file replaced by a directory, encrypted/synced storage returning transient read errors, or race with an external process removing the file.","solutions":["Fix read permissions on the policy file (chmod u+r / correct owner)","Verify the path is a regular file, not a directory or broken special file","Re-run the command if the failure was transient (file being rewritten concurrently)","Recreate the policy YAML if it was deleted or corrupted"],"exampleFix":"// before\n-rw------- 1 root root policy.yaml  # read as non-root fails\n// after\nchmod 644 policy.yaml","handlingStrategy":"try-catch","validationCode":"if st, err := os.Stat(policyPath); err != nil || st.IsDir() {\n    return fmt.Errorf(\"policy path must be a readable regular file\")\n}\nif f, err := os.Open(policyPath); err != nil { return err } else { f.Close() }","typeGuard":null,"tryCatchPattern":"rules, err := cmdpolicy.LoadYAMLPolicy(fio, path)\nif err != nil {\n    if strings.Contains(err.Error(), \"read policy yaml\") {\n        // fix file permissions or recreate the file\n    }\n    return err\n}","preventionTips":["Set readable permissions (e.g. 0644) on the policy file","Ensure the path is a regular file, not a directory","Avoid concurrent rewrites; use atomic rename when updating the policy","Recreate the file if storage reported transient read errors"],"tags":["filesystem","yaml","policy"],"backgroundTag":"file-read-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"}