{"record":{"id":"2b8ce7f86571f176","repo":"ipfs/kubo","slug":"cannot-parse-mode-s-s","errorCode":null,"errorMessage":"cannot parse mode %s: %s","messagePattern":"cannot parse mode (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/rpc/apifile.go","lineNumber":171,"sourceCode":"func (f *apiFile) Mode() os.FileMode {\n\treturn f.mode\n}\n\nfunc (f *apiFile) ModTime() time.Time {\n\treturn f.mtime\n}\n\nfunc (f *apiFile) Size() (int64, error) {\n\treturn f.size, nil\n}\n\nfunc stringToFileMode(mode string) (os.FileMode, error) {\n\tif mode == \"\" {\n\t\treturn 0, nil\n\t}\n\tmode64, err := strconv.ParseUint(mode, 8, 32)\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"cannot parse mode %s: %s\", mode, err)\n\t}\n\treturn os.FileMode(uint32(mode64)), nil\n}\n\nfunc (api *UnixfsAPI) getFile(ctx context.Context, p path.Path, size int64, mode os.FileMode, mtime time.Time) (files.Node, error) {\n\tf := &apiFile{\n\t\tctx:   ctx,\n\t\tcore:  api.core(),\n\t\tsize:  size,\n\t\tpath:  p,\n\t\tmode:  mode,\n\t\tmtime: mtime,\n\t}\n\n\treturn f, f.reset()\n}\n\ntype apiIter struct {","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/client/rpc/apifile.go#L153-L189","documentation":"stringToFileMode parses a mode string (expected octal digits, e.g. '644' or '0755') returned with the file's stat into os.FileMode. If strconv.ParseUint(mode, 8, 32) fails — empty strings are handled, so this means non-octal or out-of-range characters — the error wraps the parse failure. It propagates out of Get when the daemon supplies a mode field the client cannot parse.","triggerScenarios":"Calling Get on an RPC daemon whose ls/stat response contains a malformed or non-octal mode string (e.g. 'rw-r--r--' symbolic instead of octal, or '999' with invalid octal digits); custom servers altering the field format.","commonSituations":"Proxies or re-implementations of /api/v0 that emit symbolic permission strings; cross-version drift in the ls RPC schema; tests/mocks with hand-written mode values.","solutions":["Ensure the daemon/proxy returns mode as octal digits (e.g. '644', not 'rw-r--r--')","Pin matching kubo versions on client and daemon","If you control the value, validate octal before sending: `strconv.ParseUint(m, 8, 32)`","The error already wraps the cause with %w — use errors.Is/As on the inner *strconv.NumError to diagnose"],"exampleFix":"// before\nmode := \"rw-r--r--\" // symbolic, will fail\n// after\nmode := \"0644\" // octal digits","handlingStrategy":"validation","validationCode":"if _, err := strconv.ParseUint(modeStr, 8, 32); err != nil {\n    return fmt.Errorf(\"mode %q must be octal digits\", modeStr)\n}","typeGuard":"func isOctalMode(s string) bool {\n    if s == \"\" { return true }\n    _, err := strconv.ParseUint(s, 8, 32)\n    return err == nil\n}","tryCatchPattern":"node, err := api.Unixfs().Get(ctx, p)\nif err != nil && strings.Contains(err.Error(), \"cannot parse mode\") {\n    var numErr *strconv.NumError\n    if errors.As(err, &numErr) { log.Printf(\"bad mode %q from server\", numErr.Num) }\n    // retry against an unmodified kubo daemon\n}","preventionTips":["Ensure servers/proxies emit octal mode strings ('644'), never symbolic ('rw-r--r--')","Validate mocked RPC responses in tests","Match client/daemon versions"],"tags":["go","ipfs","rpc","parsing"],"backgroundTag":"invalid-mode-parse","analyzedSha":"329838acdfafae224582930457efe80aa217afc0","analyzedAt":"2026-09-03T18:30:52.135Z","contentChangedAt":"2026-09-03T18:30:52.135Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}