{"record":{"id":"08a1da35763afa2a","repo":"juicedata/juicefs","slug":"failed-to-parse-value-as-int-v","errorCode":null,"errorMessage":"failed to parse value as int: %v","messagePattern":"failed to parse value as int: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/meta/sql.go","lineNumber":305,"sourceCode":"\tnode    map[Ino]*node\n\tsymlink map[Ino]*symlink\n\txattr   map[Ino][]*xattr\n\tedges   map[Ino][]*edge\n\tchunk   map[string]*chunk\n}\n\nfunc extractCustomConfig[T string | int](value *url.Values, key string, defaultV T) (T, error) {\n\tif value == nil {\n\t\treturn defaultV, nil\n\t}\n\tif v := value.Get(key); v != \"\" {\n\t\tvalue.Del(key)\n\t\tvar result T\n\t\tswitch any(defaultV).(type) {\n\t\tcase int:\n\t\t\tparsedInt, err := strconv.Atoi(v)\n\t\t\tif err != nil {\n\t\t\t\treturn defaultV, fmt.Errorf(\"failed to parse value as int: %v\", err)\n\t\t\t}\n\t\t\tresult = any(parsedInt).(T)\n\t\tcase string:\n\t\t\tresult = any(v).(T)\n\t\tdefault:\n\t\t\treturn defaultV, fmt.Errorf(\"unsupported type: %T\", defaultV)\n\t\t}\n\t\treturn result, nil\n\t} else {\n\t\treturn defaultV, nil\n\t}\n}\n\ntype prefixMapper struct {\n\tmapper names.Mapper\n\tprefix string\n}\n","sourceCodeStart":287,"sourceCodeEnd":323,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/pkg/meta/sql.go#L287-L323","documentation":"extractCustomConfig is a generic helper in JuiceFS's SQL metadata engine (pkg/meta/sql.go) that reads a custom query parameter from the metadata URL. When the expected value type is int, the raw string from the URL is converted with strconv.Atoi; if the user supplied a non-numeric value, the conversion fails and this error is returned so the metadata URL is rejected before a client is created.","triggerScenarios":"Creating a dbMeta client with a SQL metadata URL (MySQL/PostgreSQL/SQLite) whose custom query parameters include a key consumed as an int by extractCustomConfig, but whose value is not a valid integer (e.g. `?batch_num=abc`).","commonSituations":"Typos in the --meta URL, quoting mistakes that turn numbers into strings, copy-pasted URLs with invalid query values, shell quoting mangling digits, or users guessing undocumented parameter names/types.","solutions":["Correct the metadata URL query parameter to a valid integer value (e.g. `?batch_num=100`).","Check the JuiceFS docs/source for the exact parameter name and expected type of each custom SQL-engine setting.","Remove the invalid parameter entirely so the built-in default is used.","Retry `juicefs format`/`mount` with the corrected --meta URL."],"exampleFix":"// before\n--meta 'mysql://user:pass@host:3306/db?batch_num=abc'\n// after\n--meta 'mysql://user:pass@host:3306/db?batch_num=100'","handlingStrategy":"validation","validationCode":"// validate before handing the meta URL to JuiceFS\nn, err := strconv.Atoi(vals.Get(\"batch_num\"))\nif err != nil {\n    return fmt.Errorf(\"batch_num must be an integer, got %q\", vals.Get(\"batch_num\"))\n}\n_ = n","typeGuard":null,"tryCatchPattern":"if err != nil {\n    if strings.Contains(err.Error(), \"failed to parse value as int\") {\n        // fall back to default config or exit with a clear message\n    }\n}","preventionTips":["Validate all custom query parameters with strconv before building the meta URL.","Keep documented parameter names/types in a reference table and review mount commands against it.","Quote the whole --meta argument in shell scripts to avoid mangling values.","Test the exact URL with `juicefs format` before production rollout."],"tags":["go","metadata","url-parsing","configuration"],"backgroundTag":"invalid-argument-value","analyzedSha":"c9a67b23e8e08ec23ec331aa6f1675e2319e921c","analyzedAt":"2026-09-06T17:55:48.476Z","contentChangedAt":"2026-09-06T17:55:48.476Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}