{"record":{"id":"2f202392fbee3566","repo":"Billionmail/BillionMail","slug":"invalid-attr","errorCode":null,"errorMessage":"invalid attr: ","messagePattern":"invalid attr: ","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/internal/service/public/common.go","lineNumber":1567,"sourceCode":"\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t}\n\t}\n\n\treturn os.Chmod(path, mode)\n}\n\n// Change file or directory attributes\nfunc Chattr(path string, attr string) error {\n\treturn ChattrRecursive(path, attr)\n}\n\n// Change file or directory attributes (recursive)\nfunc ChattrRecursive(path string, attr string) error {\n\t// Check if attr is valid\n\tif len(attr) != 2 || (attr[0] != '+' && attr[0] != '-') {\n\t\treturn errors.New(\"invalid attr: \" + attr)\n\t}\n\n\tif attr[1] != 'i' && attr[1] != 'a' && attr[1] != 'd' && attr[1] != 's' && attr[1] != 'c' {\n\t\treturn errors.New(\"invalid attr: \" + attr)\n\t}\n\n\t// File does not exist\n\tif !FileExists(path) {\n\t\treturn errors.New(\"file not exists: \" + path)\n\t}\n\n\t// Directory\n\tif IsDir(path) {\n\t\tds, err := os.ReadDir(path)\n\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}","sourceCodeStart":1549,"sourceCodeEnd":1585,"githubUrl":"https://github.com/Billionmail/BillionMail/blob/fc36c76c050c3775c5e899faf7403cf0262d2744/core/internal/service/public/common.go#L1549-L1585","documentation":"ChattrRecursive accepts an attribute string of exactly two characters: a sign ('+' or '-') followed by one of i, a, d, s, c. Anything of the wrong length, wrong sign, or unsupported flag returns \"invalid attr: <attr>\" before any filesystem access.","triggerScenarios":"Calling Chattr/ChattrRecursive with attr values like \"i\" (no sign), \"+x\" (unsupported flag), \"+ii\" (wrong length), \"++i\" (wrong sign), or an empty string.","commonSituations":"Building the attr string dynamically and dropping the sign; copying chattr CLI syntax with flags this wrapper does not support (e.g. '+u', '+e'); i18n/config files containing a single-letter flag.","solutions":["Pass a two-character string: sign plus one of i/a/d/s/c (e.g. \"+i\", \"-a\")","Validate the attr with a whitelist before calling","Map unsupported chattr CLI flags to the supported set or drop them"],"exampleFix":"// before\npublic.ChattrRecursive(path, flag) // flag = \"i\" -> invalid attr\n// after\nsign := \"+\"\nif remove { sign = \"-\" }\npublic.ChattrRecursive(path, sign+flag) // e.g. \"+i\"\n","handlingStrategy":"validation","validationCode":"func checkAttrFormat(attr string) error {\n    if len(attr) != 2 || (attr[0] != '+' && attr[0] != '-') {\n        return fmt.Errorf(\"attr must start with + or -: %q\", attr)\n    }\n    return nil\n}","typeGuard":"func hasAttrSign(s string) bool {\n    return len(s) == 2 && (s[0] == '+' || s[0] == '-')\n}","tryCatchPattern":"if err := public.Chattr(path, attr); err != nil {\n    if strings.Contains(err.Error(), \"invalid attr\") {\n        log.Errorf(\"bad attr %q from caller; expected e.g. '+i'\", attr)\n        return nil\n    }\n    return err\n}","preventionTips":["Always build attr as sign + single letter, never pass the bare letter","Type-check config values that feed Chattr (string vs decoded YAML)","Add unit tests covering '+i','-i','i','+x','','+ii'"],"tags":["filesystem","validation","chattr","input-validation"],"backgroundTag":"invalid-argument","analyzedSha":"fc36c76c050c3775c5e899faf7403cf0262d2744","analyzedAt":"2026-09-05T21:28:54.019Z","contentChangedAt":"2026-09-05T21:28:54.019Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}