jackwener/OpenCLI · error · ArgumentError

dm target must be "dm:<userId-uuid>" or "dm:@name".

Error message

dm target must be "dm:<userId-uuid>" or "dm:@name".

What it means

When the target is `dm:<something>` where the remainder is neither a UUID nor an @name, classifyTarget throws this ArgumentError. Valid forms after `dm:` are a full user UUID or a name beginning with `@`.

Source

Thrown at clis/slock/resolve.js:27

  if (!m) return null;
  return { parentTarget: m[1], parentMsgId: m[2] };
}

// Target kinds:
//   { kind: 'channel-uuid', channelId }
//   { kind: 'channel-name', name }
//   { kind: 'dm-uuid', userId }
//   { kind: 'dm-name', name }
//   { kind: 'thread', parentTarget, parentMsgId }
export function classifyTarget(raw) {
  const v = String(raw ?? '').trim();
  if (!v) throw new ArgumentError('target required: "#channel", "#channel:threadShortId", "dm:@name", "dm:<userId>", or channelId UUID.');
  if (v.startsWith('dm:')) {
    const rest = v.slice(3);
    if (!rest) throw new ArgumentError('dm target must be "dm:<userId>" or "dm:@name".');
    if (UUID_RE.test(rest)) return { kind: 'dm-uuid', userId: rest };
    if (rest.startsWith('@')) return { kind: 'dm-name', name: rest.slice(1) };
    throw new ArgumentError('dm target must be "dm:<userId-uuid>" or "dm:@name".');
  }
  const tt = classifyThreadTarget(v);
  if (tt) return { kind: 'thread', ...tt };
  if (UUID_RE.test(v)) return { kind: 'channel-uuid', channelId: v };
  return { kind: 'channel-name', name: v.replace(/^#/, '').toLowerCase() };
}

const SHORT_ID_HINT =
  'short ids (the 8-hex `msg=...` form in channel headers) are NOT accepted — use the FULL UUID ' +
  'from `bookmark-list` / `message-read` output.';

export function assertMessageIdShape(messageId) {
  const v = String(messageId ?? '').trim();
  if (!v) throw new ArgumentError('messageId required');
  if (!UUID_RE.test(v)) {
    throw new ArgumentError(`messageId "${v}" is not a full UUID. ${SHORT_ID_HINT}`);
  }
  return v;

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Prefix usernames with @: `dm:@jane`
  2. Or use the user's full UUID: `dm:123e4567-e89b-12d3-a456-426614174000`
  3. Validate the recipient format before invoking the command

Example fix

// before
$ slock message-send dm:jane "hello"
// after
$ slock message-send dm:@jane "hello"
Defensive patterns

Strategy: validation

Validate before calling

const UUID_RE = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
const t = String(target ?? '').trim();
if (t.startsWith('dm:') && !UUID_RE.test(t.slice(3)) && !t.slice(3).startsWith('@')) {
  throw new Error(`dm target must be "dm:<userId-uuid>" or "dm:@name", got "${t}"`);
}

Type guard

function isValidDmTarget(v) {
  if (typeof v !== 'string' || !v.startsWith('dm:')) return false;
  const rest = v.slice(3);
  return rest.startsWith('@') ||
    /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/.test(rest);
}

Try / catch

try {
  await cli('message-send', { target, content });
} catch (e) {
  if (e instanceof ArgumentError && e.message.includes('dm:<userId-uuid>')) {
    console.error(`"${target}" is not a valid dm form; prefix the username with @ or pass the user UUID.`);
  } else throw e;
}

Prevention

When it happens

Trigger: Passing `dm:alice` (no @ prefix), `dm:@` (bare @), `dm:#channel`, or `dm:<partial-uuid>` — anything where `UUID_RE.test(rest)` fails and `rest.startsWith('@')` is false.

Common situations: Writing `dm:jane` out of habit from other chat tools instead of `dm:@jane`; pasting a display name with spaces; using a short/incorrect user id that isn't a UUID; forgetting the @ in automation scripts.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/5179ae471126472e. Report an issue: GitHub.