debugger beta: Fix panic that could occur when parsing an invalid dap schema (#31175)

Release Notes:

- N/A
This commit is contained in:
Anthony Eid 2025-05-22 07:25:07 -04:00 committed by GitHub
parent 06f725d51b
commit 80a00cd241
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 21 additions and 6 deletions

View file

@ -375,9 +375,10 @@ pub trait DebugAdapter: 'static + Send + Sync {
) -> Result<StartDebuggingRequestArgumentsRequest> {
let map = config.as_object().context("Config isn't an object")?;
let request_variant = map["request"]
.as_str()
.ok_or_else(|| anyhow!("request is not valid"))?;
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),

View file

@ -289,7 +289,10 @@ impl DebugAdapter for GoDebugAdapter {
) -> Result<StartDebuggingRequestArgumentsRequest> {
let map = config.as_object().context("Config isn't an object")?;
let request_variant = map["request"].as_str().context("request is not valid")?;
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),

View file

@ -2,6 +2,7 @@ use adapters::latest_github_release;
use anyhow::Context as _;
use anyhow::bail;
use dap::StartDebuggingRequestArguments;
use dap::StartDebuggingRequestArgumentsRequest;
use dap::adapters::{DebugTaskDefinition, TcpArguments};
use gpui::{AsyncApp, SharedString};
use language::LanguageName;
@ -46,6 +47,13 @@ impl PhpDebugAdapter {
})
}
fn validate_config(
&self,
_: &serde_json::Value,
) -> Result<StartDebuggingRequestArgumentsRequest> {
Ok(StartDebuggingRequestArgumentsRequest::Launch)
}
async fn get_installed_binary(
&self,
delegate: &Arc<dyn DapDelegate>,
@ -93,7 +101,7 @@ impl PhpDebugAdapter {
envs: HashMap::default(),
request_args: StartDebuggingRequestArguments {
configuration: task_definition.config.clone(),
request: dap::StartDebuggingRequestArgumentsRequest::Launch,
request: self.validate_config(&task_definition.config)?,
},
})
}

View file

@ -201,7 +201,10 @@ impl DebugAdapter for PythonDebugAdapter {
) -> Result<StartDebuggingRequestArgumentsRequest> {
let map = config.as_object().context("Config isn't an object")?;
let request_variant = map["request"].as_str().context("request is not valid")?;
let request_variant = map
.get("request")
.and_then(|val| val.as_str())
.context("request is not valid")?;
match request_variant {
"launch" => Ok(StartDebuggingRequestArgumentsRequest::Launch),