debugger: Relax implementation of validate_config
to not run validation (#31785)
When we moved to schema-based debug configs, we've added validate_config - a trait method that is supposed to both validate the configuration and determine whether it is a launch configuration or an attach configuration. The validation bit is a bit problematic though - we received reports on Discords about scenarios not starting up properly; it turned out that Javascript's implementation was overly strict. Thus, I got rid of any code that tries to validate the config - let's let the debug adapter itself decide whether it can digest the configuration or not. validate_config is now left unimplemented for most DebugAdapter implementations (except for PHP), because all adapters use `request`: 'launch'/'attach' for that. Let's leave the trait method in place though, as nothing guarantees this to be true for all adapters. cc @Anthony-Eid Release Notes: - debugger: Improved error messages when the debug scenario is not valid. - debugger: Fixed cases where valid configs were rejected.
This commit is contained in:
parent
ba7b1db054
commit
a305eda8d1
11 changed files with 35 additions and 147 deletions
|
@ -370,21 +370,19 @@ pub trait DebugAdapter: 'static + Send + Sync {
|
|||
None
|
||||
}
|
||||
|
||||
fn validate_config(
|
||||
/// Extracts the kind (attach/launch) of debug configuration from the given JSON config.
|
||||
/// This method should only return error when the kind cannot be determined for a given configuration;
|
||||
/// in particular, it *should not* validate whether the request as a whole is valid, because that's best left to the debug adapter itself to decide.
|
||||
fn request_kind(
|
||||
&self,
|
||||
config: &serde_json::Value,
|
||||
) -> Result<StartDebuggingRequestArgumentsRequest> {
|
||||
let map = config.as_object().context("Config isn't an object")?;
|
||||
|
||||
let request_variant = map
|
||||
.get("request")
|
||||
.and_then(|val| val.as_str())
|
||||
.context("request argument is not found or invalid")?;
|
||||
|
||||
match request_variant {
|
||||
"launch" => Ok(StartDebuggingRequestArgumentsRequest::Launch),
|
||||
"attach" => Ok(StartDebuggingRequestArgumentsRequest::Attach),
|
||||
_ => Err(anyhow!("request must be either 'launch' or 'attach'")),
|
||||
match config.get("request") {
|
||||
Some(val) if val == "launch" => Ok(StartDebuggingRequestArgumentsRequest::Launch),
|
||||
Some(val) if val == "attach" => Ok(StartDebuggingRequestArgumentsRequest::Attach),
|
||||
_ => Err(anyhow!(
|
||||
"missing or invalid `request` field in config. Expected 'launch' or 'attach'"
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -414,7 +412,7 @@ impl DebugAdapter for FakeAdapter {
|
|||
serde_json::Value::Null
|
||||
}
|
||||
|
||||
fn validate_config(
|
||||
fn request_kind(
|
||||
&self,
|
||||
config: &serde_json::Value,
|
||||
) -> Result<StartDebuggingRequestArgumentsRequest> {
|
||||
|
@ -459,7 +457,7 @@ impl DebugAdapter for FakeAdapter {
|
|||
envs: HashMap::default(),
|
||||
cwd: None,
|
||||
request_args: StartDebuggingRequestArguments {
|
||||
request: self.validate_config(&task_definition.config)?,
|
||||
request: self.request_kind(&task_definition.config)?,
|
||||
configuration: task_definition.config.clone(),
|
||||
},
|
||||
})
|
||||
|
|
|
@ -52,7 +52,7 @@ pub fn send_telemetry(scenario: &DebugScenario, location: TelemetrySpawnLocation
|
|||
return;
|
||||
};
|
||||
let kind = adapter
|
||||
.validate_config(&scenario.config)
|
||||
.request_kind(&scenario.config)
|
||||
.ok()
|
||||
.map(serde_json::to_value)
|
||||
.and_then(Result::ok);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue