QuantumNous/new-api · error · Error
Channel is not selected
Error message
Channel is not selected
What it means
Thrown by fetchChannelKey in the channel mutate drawer when channelId is falsy at call time. The channel key endpoint requires an existing channel id (view/edit key of a saved channel), so creating-mode (channelId null/undefined/0) cannot fetch a key and fails fast with this English literal (not i18n'd).
Source
Thrown at web/src/features/channels/components/drawers/channel-mutate-drawer.tsx:1363
} else {
form.setValue('key', result.deduplicatedText)
toast.success(
t(
'Removed {{removed}} duplicate key(s). Before: {{before}}, After: {{after}}',
{
removed: result.removedCount,
before: result.beforeCount,
after: result.afterCount,
}
)
)
}
}
const fetchChannelKey = useCallback(
async (proofToken?: string) => {
if (!channelId) {
throw new Error('Channel is not selected')
}
setIsChannelKeyLoading(true)
try {
const res = await getChannelKey(channelId, proofToken)
if (!res.success) {
throw new Error(res.message || t('Failed to fetch channel key'))
}
const keyValue = res.data?.key ?? ''
setChannelKey(keyValue)
toast.success(t('Channel key unlocked'))
return res
} finally {
setIsChannelKeyLoading(false)
}
},
[channelId, t]View on GitHub (pinned to e2c7aa7b10)
Solutions
- Only render/enable the unlock-key control when channelId is a positive number (isEditing mode)
- Pass the real channel id from the row into the drawer and confirm it is set before opening the key section
- Reset drawer state (including channelId) when switching between create and edit modes
- In create mode, have the user paste the key directly — there is nothing to fetch yet
Example fix
// before
{isEditing && <Button onClick={() => fetchChannelKey()} />}
// after
{isEditing && channelId != null && (
<Button onClick={() => fetchChannelKey()} />
)} Defensive patterns
Strategy: validation
Validate before calling
if (!channelId) return // never render/enable key actions in create mode const hasChannelId = channelId != null && channelId > 0
Type guard
const hasSavedChannel = (id: number | string | null | undefined): id is number => typeof id === 'number' && id > 0
Prevention
- Enable the unlock-key control only in edit mode with a positive channel id
- Reset channelId state when the drawer closes or switches purpose
- Treat this throw as an invariant violation — fix the caller, do not catch it
When it happens
Trigger: The unlock/view key action is invoked while the drawer is in create mode (channelId not yet assigned), or the id prop was never passed/propagated to this drawer instance.
Common situations: Component race where the key button renders before the id resolves; drawer reused for create after editing (stale closure or unreset state); caller passes id=0/undefined instead of null and the falsy check still trips.
Related errors
- Failed to fetch channel key
- Parameter override must be valid JSON format
- Legacy format must be a JSON object
- Failed to refresh credential
- No channel selected
AI-assisted analysis of QuantumNous/new-api@e2c7aa7b10 (2026-08-15).
Data as JSON: /api/errors/b0094af13f542e33.
Report an issue: GitHub.