jackwener/OpenCLI · error · ArgumentError
target required: "#channel", "#channel:threadShortId", "dm:@
Error message
target required: "#channel", "#channel:threadShortId", "dm:@name", "dm:<userId>", or channelId UUID.
What it means
classifyTarget parses the positional `target` argument for Slock commands; when the value is empty after trimming, it throws this ArgumentError listing all accepted target forms. The command cannot resolve a channel, DM, or thread without a target string.
Source
Thrown at clis/slock/resolve.js:21
export 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}$/;
// ThreadTarget shape: { parentTarget: string, parentMsgId: string }
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) {View on GitHub (pinned to 49907e53dc)
Solutions
- Provide a valid target: `#channel`, `#channel:threadId`, `dm:@name`, `dm:<userId-uuid>`, or a channel UUID
- Check the script/variable that supplies the target is not empty
- Quote the target in the shell: `slock message-send "#general" "hi"`
Example fix
// before
await cli('message-send', { target: '', content: 'hi' });
// after
await cli('message-send', { target: '#general', content: 'hi' }); Defensive patterns
Strategy: validation
Validate before calling
const target = String(process.argv[2] ?? '').trim();
if (!target) throw new Error('target required: "#channel", "#channel:threadId", "dm:@name", "dm:<userId>", or channelId UUID'); Type guard
function isValidTarget(v) {
if (typeof v !== 'string') return false;
const s = v.trim();
if (!s) return false;
if (s.startsWith('dm:')) return s.length > 3;
return /^#/.test(s) || /^[0-9a-fA-F-]{6,}$/.test(s);
} Try / catch
try {
await cli('message-send', { target, content });
} catch (e) {
if (e instanceof ArgumentError && e.message.startsWith('target required')) {
console.error('No target given; supply #channel, dm:@name, dm:<uuid>, or a channel UUID.');
} else throw e;
} Prevention
- Check that the variable supplying the target is non-empty before invoking
- Quote target arguments in the shell so empty values are visible
- For programmatic use, fail early on falsy targets with a clear message
- Keep target formats documented next to script entry points
When it happens
Trigger: Calling a command that classifies its target (e.g. message-send) with an empty positional: `slock message-send "" "hello"`, or a kwargs.target that is undefined/null coerced to '' via `String(raw ?? '')`.
Common situations: Script variable for the channel unset; quoting mistake passing an empty string; piping empty input into the target slot; calling the CLI programmatically and omitting kwargs.target.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- <train-no> must not be empty
- keyword must not be empty
- <from> station must not be empty
- <to> station must not be empty
- who 不能为空
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/dbb4b52adf6efa91.
Report an issue: GitHub.