shadowsocks/shadowsocks-rust · error
`method` is required
Error message
`method` is required
What it means
Same branch as error 173: when SERVER_ADDR is provided, the code insists ENCRYPT_METHOD exists via .expect("`method` is required"). A per-server cipher is mandatory to construct ServerConfig, so a missing method aborts the process. clap's validation normally prevents this; the expect is a backstop.
Source
Thrown at src/service/local.rs:634
}
None => {
logging::init_with_config("sslocal", &service_config.log);
}
}
trace!("{:?}", service_config);
let mut config = match config_path_opt {
Some(cpath) => Config::load_from_file(&cpath, ConfigType::Local)
.map_err(|err| ShadowsocksError::LoadConfigFailure(format!("loading config {cpath:?}, {err}")))?,
None => Config::new(ConfigType::Local),
};
if let Some(svr_addr) = matches.get_one::<String>("SERVER_ADDR") {
let method = matches
.get_one::<String>("ENCRYPT_METHOD")
.map(|x| x.parse::<CipherKind>().expect("method"))
.expect("`method` is required");
let password = match matches.get_one::<String>("PASSWORD") {
Some(pwd) => read_variable_field_value(pwd).into(),
None => {
// NOTE: svr_addr should have been checked by crate::vparser
if method.is_none() {
// If method doesn't need a key (none, plain), then we can leave it empty
String::new()
} else {
match crate::password::read_server_password(svr_addr) {
Ok(pwd) => pwd,
Err(..) => panic!("`password` is required for server {svr_addr}"),
}
}
}
};
let svr_addr = svr_addr.parse::<ServerAddr>().expect("server-addr");View on GitHub (pinned to 8eb0f0a65b)
Solutions
- Add --encrypt-method <cipher> (e.g. aes-256-gcm) whenever a SERVER_ADDR is specified.
- Use a config file (-c) that includes a server entry with its own "method" field.
- If invoking create programmatically, supply "ENCRYPT_METHOD" in the matches.
Example fix
// before sslocal -b 127.0.0.1:1080 -s example.com:8388 -k secret // after sslocal -b 127.0.0.1:1080 -s example.com:8388 -k secret --encrypt-method aes-256-gcm
Defensive patterns
Strategy: validation
Validate before calling
if matches.get_one::<String>("SERVER_ADDR").is_some()
&& matches.get_one::<String>("ENCRYPT_METHOD").is_none()
{
return Err("--encrypt-method is required when SERVER_ADDR is given".into());
} Try / catch
let Some(s) = matches.get_one::<String>("ENCRYPT_METHOD") else {
eprintln!("`method` is required");
return ExitCode::FAILURE;
}; Prevention
- Use -c config.json with per-server "method" fields instead of CLI-only setups.
- Add a launcher-script check that --encrypt-method is present whenever -s is used.
- Document required flag pairings in deployment runbooks.
When it happens
Trigger: Running sslocal with SERVER_ADDR set but no --encrypt-method flag, or calling local::create programmatically with ArgMatches lacking ENCRYPT_METHOD.
Common situations: Command lines copied from AEAD-free examples; scripts that drop the method flag when SERVER_ADDR is set; hand-built ArgMatches in tests.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- `method` is required
- method
- method
- server-addr
- plugin-mode must be one of `tcp_only` (default), `udp_only`
AI-assisted analysis of shadowsocks/shadowsocks-rust@8eb0f0a65b (2026-09-09).
Data as JSON: /api/errors/d25e236bbc21d4c9.
Report an issue: GitHub.