{"record":{"id":"d4bf1f7493a55236","repo":"shadowsocks/shadowsocks-rust","slug":"method-is-required","errorCode":null,"errorMessage":"`method` is required","messagePattern":"`method` is required","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/service/genkey.rs","lineNumber":31,"sourceCode":"        Arg::new(\"ENCRYPT_METHOD\")\n            .short('m')\n            .long(\"encrypt-method\")\n            .num_args(1)\n            .action(ArgAction::Set)\n            .required(true)\n            .value_parser(PossibleValuesParser::new(available_ciphers()))\n            .help(\"Server's encryption method\"),\n    );\n\n    app\n}\n\n/// Program entrance `main`\npub fn main(matches: &ArgMatches) -> ExitCode {\n    let method = matches\n        .get_one::<String>(\"ENCRYPT_METHOD\")\n        .map(|x| x.parse::<CipherKind>().expect(\"method\"))\n        .expect(\"`method` is required\");\n\n    let key_len = method.key_len();\n    if key_len > 0 {\n        let mut key = vec![0u8; key_len];\n        rand::fill(key.as_mut_slice());\n\n        let encoded_key = base64::engine::general_purpose::STANDARD.encode(&key);\n        println!(\"{encoded_key}\");\n    }\n\n    ExitCode::SUCCESS\n}\n","sourceCodeStart":13,"sourceCodeEnd":44,"githubUrl":"https://github.com/shadowsocks/shadowsocks-rust/blob/8eb0f0a65b1d976ab6bed5787327ef86529b0435/src/service/genkey.rs#L13-L44","documentation":"get_one::<String>(\"ENCRYPT_METHOD\") returns None when the required encrypt-method argument was not supplied, and .expect(\"`method` is required\") panics with this message. Normally clap's required-argument validation catches this first; the expect is a defensive backstop.","triggerScenarios":"Invoking the genkey subcommand without the ENCRYPT_METHOD positional/option, bypassing clap validation (e.g. calling service::genkey::main programmatically with hand-built ArgMatches).","commonSituations":"Programmatic calls into the service main with hand-constructed matches; script wrappers dropping an argument; clap config regressions that made the arg optional.","solutions":["Pass the encrypt-method argument on the command line, e.g. `genkey aes-256-gcm`.","If calling genkey::main programmatically, insert \"ENCRYPT_METHOD\" into the ArgMatches.","Ensure clap's arg definition marks ENCRYPT_METHOD as required so clap reports it cleanly."],"exampleFix":"// before\nlet matches = cmd.try_get_matches_from([\"genkey\"])?;\ngenkey::main(&matches);\n\n// after\nlet matches = cmd.try_get_matches_from([\"genkey\", \"aes-256-gcm\"])?;\ngenkey::main(&matches);","handlingStrategy":"validation","validationCode":"// before calling genkey entry point programmatically\nif matches.get_one::<String>(\"ENCRYPT_METHOD\").is_none() {\n    return Err(\"genkey requires an encrypt-method argument\".into());\n}","typeGuard":null,"tryCatchPattern":"let method = matches.get_one::<String>(\"ENCRYPT_METHOD\")\n    .ok_or_else(|| anyhow!(\"`method` is required\"))?;","preventionTips":["Always pass the method positionally: `genkey aes-256-gcm`.","Keep clap arg definitions marked required so clap errors cleanly before this expect.","In script wrappers, quote and verify all arguments before exec."],"tags":["cli","rust","missing-argument","panic"],"backgroundTag":"missing-required-argument","analyzedSha":"8eb0f0a65b1d976ab6bed5787327ef86529b0435","analyzedAt":"2026-09-09T12:20:43.168Z","contentChangedAt":"2026-09-09T12:20:43.168Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}