shadowsocks/shadowsocks-rust · error

method

Error message

method

What it means

In the manager service `create`, a user-supplied `ENCRYPT_METHOD` CLI value is parsed with `m.parse::<CipherKind>().expect("method")`. The panic means the string is not a recognized shadowsocks cipher name (e.g. typo or an unsupported algorithm). Parsing happens only when `--encrypt-method` is provided on the command line.

Source

Thrown at src/service/manager.rs:367

                _ => {
                    config.manager = Some(ManagerConfig::new(addr));
                }
            }
        }

        #[cfg(all(unix, not(target_os = "android")))]
        match matches.get_one::<u64>("NOFILE") {
            Some(nofile) => config.nofile = Some(*nofile),
            None => {
                if config.nofile.is_none() {
                    crate::sys::adjust_nofile();
                }
            }
        }

        if let Some(ref mut manager_config) = config.manager {
            if let Some(m) = matches.get_one::<String>("ENCRYPT_METHOD").cloned() {
                manager_config.method = Some(m.parse::<CipherKind>().expect("method"));
            }

            if let Some(t) = matches.get_one::<u64>("TIMEOUT") {
                manager_config.timeout = Some(Duration::from_secs(*t));
            }

            if let Some(sh) = matches.get_one::<ManagerServerHost>("SERVER_HOST").cloned() {
                manager_config.server_host = sh;
            }

            if let Some(p) = matches.get_one::<String>("PLUGIN").cloned() {
                manager_config.plugin = Some(PluginConfig {
                    plugin: p,
                    plugin_opts: matches.get_one::<String>("PLUGIN_OPT").cloned(),
                    plugin_args: Vec::new(),
                    plugin_mode: matches
                        .get_one::<String>("PLUGIN_MODE")
                        .map(|x| {

View on GitHub (pinned to 8eb0f0a65b)

Solutions

  1. Use a supported AEAD cipher name exactly, e.g. `aes-256-gcm`, `chacha20-ietf-poly1305`, `2022-blake3-aes-256-gcm`
  2. Match casing/spacing exactly as listed in shadowsocks-rust's CipherKind docs (lowercase, hyphenated)
  3. Remove `--encrypt-method` to fall back to the config-file value
  4. Check feature flags — some ciphers require enabling cargo features

Example fix

// before
--encrypt-method "AES-256-GCM"
// after
--encrypt-method "aes-256-gcm"
Defensive patterns

Strategy: validation

Validate before calling

const VALID: &[&str] = &["aes-128-gcm","aes-256-gcm","chacha20-ietf-poly1305","2022-blake3-aes-128-gcm","2022-blake3-aes-256-gcm","2022-blake3-chacha8-poly1305","2022-blake3-chacha20-poly1305"];
assert!(VALID.contains(&method_str), "unsupported cipher: {method_str}");

Type guard

fn is_supported_cipher(s: &str) -> bool {
    matches!(s, "aes-128-gcm" | "aes-256-gcm" | "chacha20-ietf-poly1305")
}

Try / catch

// parse instead of expect when embedding the logic
let kind: CipherKind = m.parse().map_err(|e| format!("invalid --encrypt-method: {e}"))?;

Prevention

When it happens

Trigger: Passing `--encrypt-method` with a value that fails `CipherKind::from_str`, such as "aes-256-cfb", "rc4", "AES-256-GCM" (uppercase not matching), or any cipher not compiled in.

Common situations: Copy-pasting cipher names from older shadowsocks docs (legacy stream ciphers removed), wrong casing, using cipher names from other tools (e.g. wireguard or openvpn ciphers).

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of shadowsocks/shadowsocks-rust@8eb0f0a65b (2026-09-09). Data as JSON: /api/errors/8985085bbb560f90. Report an issue: GitHub.