{"record":{"id":"b781f6012dd4ccb3","repo":"shadowsocks/shadowsocks-rust","slug":"method-is-required-b781f6","errorCode":null,"errorMessage":"`method` is required","messagePattern":"`method` is required","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/service/server.rs","lineNumber":337,"sourceCode":"            }\n            None => {\n                logging::init_with_config(\"ssserver\", &service_config.log);\n            }\n        }\n\n        trace!(\"{:?}\", service_config);\n\n        let mut config = match config_path_opt {\n            Some(cpath) => Config::load_from_file(&cpath, ConfigType::Server)\n                .map_err(|err| ShadowsocksError::LoadConfigFailure(format!(\"loading config {cpath:?}, {err}\")))?,\n            None => Config::new(ConfigType::Server),\n        };\n\n        if let Some(svr_addr) = matches.get_one::<String>(\"SERVER_ADDR\") {\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 password = match matches.get_one::<String>(\"PASSWORD\") {\n                Some(pwd) => read_variable_field_value(pwd).into(),\n                None => {\n                    // NOTE: svr_addr should have been checked by crate::vparser\n                    if method.is_none() {\n                        // If method doesn't need a key (none, plain), then we can leave it empty\n                        String::new()\n                    } else {\n                        match crate::password::read_server_password(svr_addr) {\n                            Ok(pwd) => pwd,\n                            Err(..) => panic!(\"`password` is required for server {svr_addr}\"),\n                        }\n                    }\n                }\n            };\n\n            let svr_addr = svr_addr.parse::<ServerAddr>().expect(\"server-addr\");","sourceCodeStart":319,"sourceCodeEnd":355,"githubUrl":"https://github.com/shadowsocks/shadowsocks-rust/blob/8eb0f0a65b1d976ab6bed5787327ef86529b0435/src/service/server.rs#L319-L355","documentation":"After mapping the optional `ENCRYPT_METHOD` value, the code calls `.expect(\"`method` is required\")`. This panics when `--server-addr` was given on the CLI but `--encrypt-method` was not — the inner map produced None. The server requires a cipher method when a server is defined via command-line arguments.","triggerScenarios":"Running `ssserver -s 0.0.0.0:8388 -p password` without `--encrypt-method`/-m; the server address path is taken but no method was supplied.","commonSituations":"New users omitting `-m` because a config file normally supplies it; scripts that pass the server address but forget the method; migrating from tools with implicit default ciphers.","solutions":["Add `--encrypt-method aes-256-gcm` (or another supported cipher) to the command line","Or use a config file with the `method` field instead of CLI flags","In scripts, assert the method variable is non-empty before invoking ssserver"],"exampleFix":"// before\nssserver -s \"0.0.0.0:8388\" -p \"pass\"\n// after\nssserver -s \"0.0.0.0:8388\" -p \"pass\" -m aes-256-gcm","handlingStrategy":"validation","validationCode":"// enforce method presence when server-addr is used\nif cli.server_addr.is_some() {\n    assert!(cli.method.is_some(), \"--encrypt-method is required with --server-addr\");\n}","typeGuard":"fn method_present(addr: Option<&str>, method: Option<&str>) -> bool {\n    addr.is_none() || method.is_some()\n}","tryCatchPattern":"null","preventionTips":["Always pair -s with -m when defining a server via CLI","Prefer config files, which enforce required fields with clearer errors","Add the pair check to deployment scripts"],"tags":["cli","missing-argument","encryption","shadowsocks"],"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-14T11:17:12.474Z"}