jackwener/OpenCLI · error · ArgumentError
dm target must be "dm:<userId>" or "dm:@name".
Error message
dm target must be "dm:<userId>" or "dm:@name".
What it means
When the target starts with `dm:` but nothing follows the prefix, classifyTarget throws this ArgumentError. A DM target must carry either a user UUID or an @name after the colon.
Source
Thrown at clis/slock/resolve.js:24
export function classifyThreadTarget(raw) {
const s = String(raw ?? '').trim();
const m = s.match(/^(#?[^:]+):([A-Za-z0-9-]{6,})$/);
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)) {View on GitHub (pinned to 49907e53dc)
Solutions
- Append the recipient: `dm:@username` or `dm:<user-uuid>`
- Fix the variable interpolation that dropped the user value
- Verify the target string before calling, e.g. `target.includes(':') && target.split(':')[1]`
Example fix
// before
const target = `dm:${userId}`; // userId = ''
// after
if (!userId) throw new Error('userId required for dm target');
const target = `dm:${userId}`; Defensive patterns
Strategy: validation
Validate before calling
if (/^dm:$/.test(String(target ?? '').trim())) throw new Error('dm target missing recipient; use "dm:<userId-uuid>" or "dm:@name"'); Type guard
function isDmTarget(v) {
if (typeof v !== 'string') return false;
const rest = v.trim().slice(3);
return v.trim().startsWith('dm:') && rest.length > 0 &&
(/^@/.test(rest) || /^[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 target must be')) {
console.error(`dm target "${target}" had no recipient after "dm:"; append @name or a user UUID.`);
} else throw e;
} Prevention
- Guard interpolated dm targets: throw if the user variable is empty before building `dm:${user}`
- Prefer dm-uuid form in automation for unambiguous resolution
- Sanity-check the assembled target string with a regex before invoking
- Avoid string-splitting pipelines that can drop the text after the colon
When it happens
Trigger: Passing exactly `"dm:"` (or `"dm: "` which trims... no — trailing whitespace after the colon is preserved in `rest`) — precisely, `raw` is `dm:` with an empty remainder, e.g. `slock message-send dm: "hello"` or a variable `${user}` interpolating to empty: `dm:${user}`.
Common situations: Templating bug where the user id/name variable is empty (`dm:${USER_ID}` with USER_ID unset); copy error leaving the prefix without the recipient; splitting a target string on the wrong delimiter.
Related errors
- dm target must be "dm:<userId-uuid>" or "dm:@name".
- target required: "#channel", "#channel:threadShortId", "dm:@
- <train-no> must not be empty
- <train-no> "${trainNo}" does not look like a 12306 internal
- --from station must not be empty
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/40f2c9b345822a97.
Report an issue: GitHub.