RocketChat/Rocket.Chat · error · Meteor.Error

error-invalid-channel-start-with-chars

error-invalid-channel-start-with-chars

Error message

Invalid channel. Start with @ or #

What it means

Thrown by addIncomingIntegration when any comma-separated channel entry does not start with '#' or '@' (validChannelChars = ['@', '#']). The string is split on ',' and each segment trimmed, so a segment must begin with # (room target) or @ (direct-message target). An empty segment - caused by a trailing comma or a double comma - also triggers this, because channel[0] is undefined. Quirk: the error's details.method says 'updateIncomingIntegration' even on add (copy-paste in the source), so do not key handling on details.method here.

Source

Thrown at apps/meteor/server/meteor-methods/integrations/incoming/addIncomingIntegration.ts:69

	}

	if (!integration.channel || typeof integration.channel.valueOf() !== 'string') {
		throw new Meteor.Error('error-invalid-channel', 'Invalid channel', {
			method: 'addIncomingIntegration',
		});
	}

	if (integration.channel.trim() === '') {
		throw new Meteor.Error('error-invalid-channel', 'Invalid channel', {
			method: 'addIncomingIntegration',
		});
	}

	const channels = integration.channel.split(',').map((channel) => channel.trim());

	for (const channel of channels) {
		if (!validChannelChars.includes(channel[0])) {
			throw new Meteor.Error('error-invalid-channel-start-with-chars', 'Invalid channel. Start with @ or #', {
				method: 'updateIncomingIntegration',
			});
		}
	}

	if (!integration.username || typeof integration.username.valueOf() !== 'string' || integration.username.trim() === '') {
		throw new Meteor.Error('error-invalid-username', 'Invalid username', {
			method: 'addIncomingIntegration',
		});
	}

	if (integration.script?.trim()) {
		validateScriptEngine(integration.scriptEngine ?? 'isolated-vm');
	}

	const user = await Users.findOneByUsername(integration.username, { projection: { _id: 1 } });

	if (!user) {

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Prefix every room with # and every direct target with @, e.g. '#general,#dev,@rocket.cat'
  2. Filter out empty segments before submitting: channel.split(',').map(s => s.trim()).filter(Boolean).join(',')
  3. Remove trailing/double commas from user input in the form layer

Example fix

// before
const channel = ['general', 'dev'].join(','); // 'general,dev'
// after
const channel = ['general', 'dev'].map((c) => c.trim() ? `#${c.trim().replace(/^[#@]/, '')}` : '').filter(Boolean).join(','); // '#general,#dev'
Defensive patterns

Strategy: validation

Validate before calling

const validChannelChars = ['@', '#'];
const segments = String(integration.channel ?? '').split(',').map((s) => s.trim());
const invalid = segments.filter((s) => !validChannelChars.includes(s[0]));
if (segments.some((s) => !s) || invalid.length) throw new Error(`channel entries must start with # or @: ${invalid.join(', ')}`);
await Meteor.callAsync('addIncomingIntegration', integration);

Type guard

const isValidChannelList = (c: unknown): c is string =>
  typeof c === 'string' && c.trim() !== '' &&
  c.split(',').every((s) => ['@', '#'].includes(s.trim()[0]));

Try / catch

try {
  await Meteor.callAsync('addIncomingIntegration', integration);
} catch (err) {
  if (err instanceof Meteor.Error && err.error === 'error-invalid-channel-start-with-chars') { /* highlight offending entry; note details.method is mislabeled 'updateIncomingIntegration' here */ }
}

Prevention

When it happens

Trigger: channel: 'general' (no prefix); 'general, #dev' (first entry unprefixed); '#general,' (trailing comma produces an empty segment); '#general,,#dev' (double comma).

Common situations: Users typing bare room names copied from the UI title; CSV-style input with a trailing comma; a form that joins selected channels with ',' but leaves an empty selection in the list.

Related errors


AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18). Data as JSON: /api/errors/7b59bbc25c424052. Report an issue: GitHub.