mirror of
https://github.com/harivansh-afk/sandbox-agent.git
synced 2026-04-15 07:04:48 +00:00
feat: [US-035] - Fix BrowserProblem misuse: use correct error variants for non-startup failures
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
97b5e715f2
commit
66ca6529b1
3 changed files with 18 additions and 11 deletions
|
|
@ -31,7 +31,7 @@ pub fn list_contexts(state_dir: &Path) -> Result<Vec<BrowserContextInfo>, Browse
|
|||
|
||||
let mut contexts = Vec::new();
|
||||
let entries = fs::read_dir(&base).map_err(|e| {
|
||||
BrowserProblem::start_failed(format!("failed to read contexts directory: {e}"))
|
||||
BrowserProblem::internal_error(format!("failed to read contexts directory: {e}"))
|
||||
})?;
|
||||
|
||||
for entry in entries {
|
||||
|
|
@ -78,7 +78,7 @@ pub fn create_context(
|
|||
let context_dir = base.join(&id);
|
||||
|
||||
fs::create_dir_all(&context_dir).map_err(|e| {
|
||||
BrowserProblem::start_failed(format!("failed to create context directory: {e}"))
|
||||
BrowserProblem::internal_error(format!("failed to create context directory: {e}"))
|
||||
})?;
|
||||
|
||||
let now = chrono::Utc::now().to_rfc3339();
|
||||
|
|
@ -89,11 +89,11 @@ pub fn create_context(
|
|||
};
|
||||
|
||||
let meta_bytes = serde_json::to_vec_pretty(&meta).map_err(|e| {
|
||||
BrowserProblem::start_failed(format!("failed to serialize context metadata: {e}"))
|
||||
BrowserProblem::internal_error(format!("failed to serialize context metadata: {e}"))
|
||||
})?;
|
||||
|
||||
fs::write(context_dir.join(META_FILE), meta_bytes).map_err(|e| {
|
||||
BrowserProblem::start_failed(format!("failed to write context metadata: {e}"))
|
||||
BrowserProblem::internal_error(format!("failed to write context metadata: {e}"))
|
||||
})?;
|
||||
|
||||
Ok(BrowserContextInfo {
|
||||
|
|
@ -116,7 +116,7 @@ pub fn delete_context(state_dir: &Path, context_id: &str) -> Result<(), BrowserP
|
|||
}
|
||||
|
||||
fs::remove_dir_all(&context_dir).map_err(|e| {
|
||||
BrowserProblem::start_failed(format!("failed to delete context directory: {e}"))
|
||||
BrowserProblem::internal_error(format!("failed to delete context directory: {e}"))
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
|
|
|
|||
|
|
@ -57,6 +57,11 @@ impl BrowserProblem {
|
|||
Self::new(500, "Browser Start Failed", "browser/start-failed", message)
|
||||
}
|
||||
|
||||
// 500 - internal error (filesystem, serialization, etc.)
|
||||
pub fn internal_error(message: impl Into<String>) -> Self {
|
||||
Self::new(500, "Internal Error", "browser/internal-error", message)
|
||||
}
|
||||
|
||||
// 502 - CDP communication error
|
||||
pub fn cdp_error(message: impl Into<String>) -> Self {
|
||||
Self::new(502, "CDP Error", "browser/cdp-error", message)
|
||||
|
|
|
|||
|
|
@ -301,12 +301,14 @@ impl BrowserRuntime {
|
|||
tokio::spawn(async move {
|
||||
let mut rx = console_rx;
|
||||
while let Some(params) = rx.recv().await {
|
||||
let level = params
|
||||
.get("type")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("log")
|
||||
.to_string();
|
||||
// CDP uses "warning" as type but we normalize to "warning"
|
||||
let raw_level =
|
||||
params.get("type").and_then(|v| v.as_str()).unwrap_or("log");
|
||||
// CDP uses "warning" as type but we normalize to "warn"
|
||||
let level = if raw_level == "warning" {
|
||||
"warn".to_string()
|
||||
} else {
|
||||
raw_level.to_string()
|
||||
};
|
||||
let args = params
|
||||
.get("args")
|
||||
.and_then(|v| v.as_array())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue