t8y2/dbx · error

ETCD_NEWKEY_REQUIRED

ETCD_NEWKEY_REQUIRED

Error message

ETCD_NEWKEY_REQUIRED

What it means

Required-parameter error thrown by rename at kv.go:381. Renaming a key needs a target path, and the driver enforces that the newKey parameter is present and non-empty; otherwise it returns this bare sentinel code. It is a pure input validation — no etcd call is made.

Source

Thrown at agents/drivers/etcd-go/kv.go:381

	response, err := client.Delete(ctx, key)
	if err != nil {
		return nil, err
	}
	return map[string]any{"deleted": response.Deleted, "revision": longString(response.Header.Revision)}, nil
}

func (s *etcdSession) rename(params map[string]json.RawMessage) (any, error) {
	client, err := s.activeClient()
	if err != nil {
		return nil, err
	}
	sourceKey, err := keyBytesParam(params)
	if err != nil {
		return nil, err
	}
	newKey := stringOrNull(params, "newKey")
	if newKey == nil || *newKey == "" {
		return nil, errors.New("ETCD_NEWKEY_REQUIRED")
	}
	targetKey := *newKey
	if sourceKey == targetKey {
		return map[string]any{"renamed": true, "revision": nil}, nil
	}

	ctx, cancel := s.beginOperation()
	defer s.endOperation(cancel)
	sourceResponse, err := client.Get(ctx, sourceKey)
	if err != nil {
		return nil, err
	}
	if len(sourceResponse.Kvs) == 0 {
		return nil, errors.New("ETCD_NOT_FOUND: source key does not exist")
	}
	source := sourceResponse.Kvs[0]
	expected := longOrNull(params, "expectedModRevision")
	expectedRevision := source.ModRevision

View on GitHub (pinned to c0390bff16)

Solutions

  1. Pass a non-empty newKey string, e.g. rename(session, 'old/key', { newKey: 'new/key' }).
  2. Validate newKey truthiness in caller code before invoking rename.
  3. If you meant a copy instead of a rename, supply the destination path explicitly.
  4. Fix upstream defaults so the target name is always populated.

Example fix

// before
rename(session, key, { newKey: newName }); // newName === ''
// after
if (!newName) throw new Error('destination key required');
rename(session, key, { newKey: newName });
Defensive patterns

Strategy: validation

Validate before calling

if (typeof newKey !== 'string' || newKey.length === 0) {
  throw new Error('rename requires a non-empty newKey');
}

Type guard

function hasValidNewKey(p) { return typeof p.newKey === 'string' && p.newKey.length > 0; }

Try / catch

try { return rename(session, sourceKey, { newKey }); }
catch (e) {
  if (String(e).includes('ETCD_NEWKEY_REQUIRED'))
    throw new Error('caller bug: rename invoked without destination key');
  throw e;
}

Prevention

When it happens

Trigger: Calling the rename operation without a newKey parameter, with newKey: "", or with newKey: null/undefined.

Common situations: Dynamically built params objects where the target name variable was empty/undefined; form/UI submissions with a blank destination field; renaming scripts missing a required argument.

Understand the failure class

Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.

Related errors


AI-assisted analysis of t8y2/dbx@c0390bff16 (2026-09-05). Data as JSON: /api/errors/0527068f71bcd34d. Report an issue: GitHub.