juicedata/juicefs · warning

object key cannot be empty

Error message

object key cannot be empty

What it means

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.

Source

Thrown at pkg/object/mem.go:56

}

type memStore struct {
	sync.Mutex
	DefaultObjectStorage
	name    string
	objects map[string]*mobj
}

func (m *memStore) String() string {
	return fmt.Sprintf("mem://%s/", m.name)
}

func (m *memStore) Head(ctx context.Context, key string) (Object, error) {
	m.Lock()
	defer m.Unlock()
	// Minimum length is 1.
	if key == "" {
		return nil, errors.New("object key cannot be empty")
	}
	o, ok := m.objects[key]
	if !ok {
		return nil, os.ErrNotExist
	}
	f := &file{
		obj{
			key,
			int64(len(o.data)),
			o.mtime,
			strings.HasSuffix(key, "/"),
			"", "",
		},
		o.owner,
		o.group,
		o.mode,
		false,
	}

View on GitHub (pinned to c9a67b23e8)

Solutions

  1. Fix the caller to never produce an empty object key; validate/format the chunk path before calling Head.
  2. Check that the chunk prefix/dir configuration (e.g. --storage-dir or bucket prefix) is set so composed keys are non-empty.
  3. In tests, assert key non-empty or use a real key before invoking Head.

Example fix

// before
o, err := store.Head(ctx, key) // key == ""
// after
if key == "" {
    return nil, fmt.Errorf("cannot head object: key is empty")
}
o, err := store.Head(ctx, key)
Defensive patterns

Strategy: validation

Validate before calling

if key == "" {
    return nil, fmt.Errorf("refusing Head: empty object key")
}
return store.Head(ctx, key)

Try / catch

o, err := store.Head(ctx, key)
if err != nil {
    if strings.Contains(err.Error(), "key cannot be empty") {
        return nil, fmt.Errorf("programming bug: empty key composed for object storage")
    }
    return err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of juicedata/juicefs@c9a67b23e8 (2026-09-06). Data as JSON: /api/errors/4dfcc1ae0a34f512. Report an issue: GitHub.