libnyanpasu/clash-nyanpasu · error · Error

Script mode is only available for Clash Premium

Error message

Script mode is only available for Clash Premium

What it means

The proxy-mode upsert in use-proxy-mode.ts rejects 'script' mode unless the active clash core is 'clash' (Clash Premium). Script mode is a Premium-only feature, so any other core (mihomo, clash-rs, etc.) cannot process it and the client fails fast with this explicit error instead of sending an invalid config.

Source

Thrown at frontend/interface/src/ipc/use-proxy-mode.ts:55

    const currentMode = clashConfig.query.data?.mode?.toLowerCase()

    if (
      currentMode &&
      Object.prototype.hasOwnProperty.call(modes, currentMode)
    ) {
      modes[currentMode as keyof typeof modes] = true
    } else {
      modes.rule = true
    }

    return modes
  }, [clashConfig.query.data, clashCore.value])

  const upsert = async (mode: ProxyMode) => {
    // only clash premium support script mode
    if (clashCore.value !== 'clash' && mode === 'script') {
      throw new Error('Script mode is only available for Clash Premium')
    }

    await clashConfig.upsert.mutateAsync({ mode })
  }

  return {
    value,
    upsert,
  }
}

View on GitHub (pinned to f7dbce2997)

Solutions

  1. Switch the clash core to Clash Premium ('clash') before enabling script mode
  2. Choose a non-script proxy mode (rule/global) compatible with the current core
  3. Guard the UI so script mode is only selectable when the core is 'clash'

Example fix

// before
await upsert('script')
// after
if (clashCore.value === 'clash') {
  await upsert('script')
} else {
  await upsert('rule')
}
Defensive patterns

Strategy: validation

Validate before calling

if (clashCore.value !== 'clash' && mode === 'script') {
  throw new Error('Switch to Clash Premium to use script mode')
}

Type guard

const canUseScriptMode = (core: string): core is 'clash' => core === 'clash'

Try / catch

try {
  await upsert(mode)
} catch (e) {
  if (e instanceof Error && e.message.includes('Script mode')) {
    showToast('Script mode requires Clash Premium')
  }
}

Prevention

When it happens

Trigger: Calling upsert('script') while clashCore.value is anything other than 'clash', e.g. after switching the core to mihomo or clash-rs and then selecting script mode in the UI or via the mutation.

Common situations: Users switch from Clash Premium to mihomo/clash-meta while a script mode was in use, or attempt to enable script mode on an open-source core that lacks the script engine.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of libnyanpasu/clash-nyanpasu@f7dbce2997 (2026-09-08). Data as JSON: /api/errors/b6fe1f20a59c25c4. Report an issue: GitHub.