{"record":{"id":"ba58ad146e9b0320","repo":"astrid-runtime/astrid","slug":"resolve-selected-workspace-e","errorCode":null,"errorMessage":"resolve selected workspace: {e}","messagePattern":"resolve selected workspace: (.+?)","errorType":"http","errorClass":"GatewayError::Internal","httpStatus":500,"severity":"error","filePath":"crates/astrid-gateway/src/routes/env.rs","lineNumber":380,"sourceCode":") -> GatewayResult<HashMap<String, EnvFieldSchema>> {\n    // Principal installs override workspace capsules, matching runtime\n    // discovery. The manifest is read only after `ensure_capsule_visible` has\n    // confirmed that the same principal is allowed to see the capsule.\n    let principal_manifest = home\n        .principal_home(principal)\n        .capsules_dir()\n        .join(capsule_id)\n        .join(\"Capsule.toml\");\n    if principal_manifest.exists() {\n        return parse_env_schema(&principal_manifest);\n    }\n\n    let Some(workspace_root) = workspace_root else {\n        return Err(GatewayError::NotFound);\n    };\n    let workspace = workspace_layout\n        .resolve(workspace_root)\n        .map_err(|e| GatewayError::Internal(anyhow::anyhow!(\"resolve selected workspace: {e}\")))?;\n    let manifest_relative = FsPath::new(\"capsules\")\n        .join(capsule_id)\n        .join(\"Capsule.toml\");\n    let workspace_manifest = workspace.resolve_file(&manifest_relative).map_err(|e| {\n        GatewayError::Internal(anyhow::anyhow!(\"resolve workspace capsule manifest: {e}\"))\n    })?;\n    if !workspace_manifest.exists() {\n        return Err(GatewayError::NotFound);\n    }\n    let schema = parse_env_schema(&workspace_manifest)?;\n    workspace.resolve_file(&manifest_relative).map_err(|e| {\n        GatewayError::Internal(anyhow::anyhow!(\n            \"workspace capsule manifest changed while it was being read: {e}\"\n        ))\n    })?;\n    Ok(schema)\n}\n","sourceCodeStart":362,"sourceCodeEnd":398,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-gateway/src/routes/env.rs#L362-L398","documentation":"load_env_schema_from_home_in_workspace resolves the selected workspace root through workspace_layout.resolve and wraps any resolution failure as an Internal error. The workspace root was supplied by the caller, but the layout layer could not turn it into a valid workspace (bad path, missing markers, IO problems).","triggerScenarios":"Calling load_env_schema_from_home (directly or via the env-schema route/tests) with a workspace_root that workspace_layout.resolve cannot resolve — e.g. a path that doesn't exist, is not a directory, or lacks required workspace structure.","commonSituations":"Stale or deleted workspace root recorded in home config; workspace directory moved or renamed; permission problems on the workspace path; typo'd workspace id in the request.","solutions":["Verify the workspace root path exists and is a valid workspace directory, then retry","Re-register or re-select the correct workspace so home config points at a live root","Check filesystem permissions on the workspace path"],"exampleFix":"// before\nlet workspace = workspace_layout\n    .resolve(workspace_root)\n    .map_err(|e| GatewayError::Internal(anyhow::anyhow!(\"resolve selected workspace: {e}\")))?;\n// after\nlet workspace = workspace_layout.resolve(workspace_root).map_err(|e| {\n    tracing::warn!(root = %workspace_root.display(), error = %e, \"workspace resolve failed\");\n    GatewayError::NotFound\n})?;","handlingStrategy":"validation","validationCode":"let root = std::path::PathBuf::from(&workspace_root);\nif !root.is_dir() {\n    return Err(GatewayError::NotFound);\n}","typeGuard":"fn is_valid_workspace_root(p: &FsPath) -> bool {\n    p.is_dir() && p.join(\"capsules\").is_dir()\n}","tryCatchPattern":"match load_env_schema_from_home(state, &capsule_id).await {\n    Ok(schema) => schema,\n    Err(GatewayError::Internal(e)) if e.to_string().starts_with(\"resolve selected workspace\") => {\n        // workspace root is stale; ask the user to re-select a workspace\n        workspace_selection_required()\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Validate the workspace root exists and looks like a workspace before serving env schema requests","Clean up stale workspace entries in home config when directories are moved/deleted","Restrict workspace_root inputs to registered, previously-resolved workspaces"],"tags":["rust","workspace","filesystem","gateway"],"backgroundTag":"invalid-config-value","analyzedSha":"affd8760f44190dbdfbec23403f4c4b642c33112","analyzedAt":"2026-09-09T21:28:12.402Z","contentChangedAt":"2026-09-09T21:28:12.402Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}