{"record":{"id":"4dfcc1ae0a34f512","repo":"juicedata/juicefs","slug":"object-key-cannot-be-empty","errorCode":null,"errorMessage":"object key cannot be empty","messagePattern":"object key cannot be empty","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/object/mem.go","lineNumber":56,"sourceCode":"}\n\ntype memStore struct {\n\tsync.Mutex\n\tDefaultObjectStorage\n\tname    string\n\tobjects map[string]*mobj\n}\n\nfunc (m *memStore) String() string {\n\treturn fmt.Sprintf(\"mem://%s/\", m.name)\n}\n\nfunc (m *memStore) Head(ctx context.Context, key string) (Object, error) {\n\tm.Lock()\n\tdefer m.Unlock()\n\t// Minimum length is 1.\n\tif key == \"\" {\n\t\treturn nil, errors.New(\"object key cannot be empty\")\n\t}\n\to, ok := m.objects[key]\n\tif !ok {\n\t\treturn nil, os.ErrNotExist\n\t}\n\tf := &file{\n\t\tobj{\n\t\t\tkey,\n\t\t\tint64(len(o.data)),\n\t\t\to.mtime,\n\t\t\tstrings.HasSuffix(key, \"/\"),\n\t\t\t\"\", \"\",\n\t\t},\n\t\to.owner,\n\t\to.group,\n\t\to.mode,\n\t\tfalse,\n\t}","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/pkg/object/mem.go#L38-L74","documentation":"The in-memory object store (memStore, used mainly for tests) rejects Head calls with an empty key string, since an empty string cannot be a valid object key. It returns this error instead of looking up the map.","triggerScenarios":"Calling memStore.Head(ctx, \"\") — e.g. a caller that built a key from empty path components, a chunk path formatter producing \"\", or test code passing an uninitialized key.","commonSituations":"Unit tests exercising the chunk/cache layer with mem backend and an unset chunk prefix; code paths joining empty dir/key segments; regressions in key-formatting logic.","solutions":["Fix the caller to never produce an empty object key; validate/format the chunk path before calling Head.","Check that the chunk prefix/dir configuration (e.g. --storage-dir or bucket prefix) is set so composed keys are non-empty.","In tests, assert key non-empty or use a real key before invoking Head."],"exampleFix":"// before\no, err := store.Head(ctx, key) // key == \"\"\n// after\nif key == \"\" {\n    return nil, fmt.Errorf(\"cannot head object: key is empty\")\n}\no, err := store.Head(ctx, key)","handlingStrategy":"validation","validationCode":"if key == \"\" {\n    return nil, fmt.Errorf(\"refusing Head: empty object key\")\n}\nreturn store.Head(ctx, key)","typeGuard":null,"tryCatchPattern":"o, err := store.Head(ctx, key)\nif err != nil {\n    if strings.Contains(err.Error(), \"key cannot be empty\") {\n        return nil, fmt.Errorf(\"programming bug: empty key composed for object storage\")\n    }\n    return err\n}","preventionTips":["Validate chunk/object key composition (prefix + id) before storage calls.","Assert non-empty keys in unit tests using the mem backend.","Set all prefix/bucket config so key builders never yield empty strings."],"tags":["object-storage","in-memory","validation","testing"],"backgroundTag":"null-argument","analyzedSha":"c9a67b23e8e08ec23ec331aa6f1675e2319e921c","analyzedAt":"2026-09-06T17:55:48.476Z","contentChangedAt":"2026-09-06T17:55:48.476Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}