{"record":{"id":"649b2b7728892854","repo":"BloopAI/vibe-kanban","slug":"workspace-path-should-be-valid","errorCode":null,"errorMessage":"Workspace path should be valid","messagePattern":"Workspace path should be valid","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/services/src/services/events/patches.rs","lineNumber":70,"sourceCode":"    }\n}\n\n/// Helper functions for creating workspace-specific patches\npub mod workspace_patch {\n    use super::*;\n\n    fn workspace_path(workspace_id: Uuid) -> String {\n        format!(\n            \"/workspaces/{}\",\n            escape_pointer_segment(&workspace_id.to_string())\n        )\n    }\n\n    pub fn add(workspace: &WorkspaceWithStatus) -> Patch {\n        Patch(vec![PatchOperation::Add(AddOperation {\n            path: workspace_path(workspace.id)\n                .try_into()\n                .expect(\"Workspace path should be valid\"),\n            value: serde_json::to_value(workspace)\n                .expect(\"Workspace serialization should not fail\"),\n        })])\n    }\n\n    pub fn replace(workspace: &WorkspaceWithStatus) -> Patch {\n        Patch(vec![PatchOperation::Replace(ReplaceOperation {\n            path: workspace_path(workspace.id)\n                .try_into()\n                .expect(\"Workspace path should be valid\"),\n            value: serde_json::to_value(workspace)\n                .expect(\"Workspace serialization should not fail\"),\n        })])\n    }\n\n    pub fn remove(workspace_id: Uuid) -> Patch {\n        Patch(vec![PatchOperation::Remove(RemoveOperation {\n            path: workspace_path(workspace_id)","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/BloopAI/vibe-kanban/blob/4deb7eca8f381f7cbc1f9d15515a9ab8f8009053/crates/services/src/services/events/patches.rs#L52-L88","documentation":"This panic comes from an `.expect()` on the JSON Pointer string conversion in `workspace_patch::add` (crates/services/src/services/events/patches.rs:70). `workspace_path()` builds a pointer of the form \"/workspaces/<uuid>\" with `~` and `/` escaped via `escape_pointer_segment`, so `try_into()` into the json_patch `Pointer` type should always succeed. The panic only fires if the constructed path is not a valid JSON Pointer (not starting with `/` or containing unescaped invalid segments), which indicates a bug in the path-building helper rather than bad caller input.","triggerScenarios":"Calling `workspace_patch::add(&WorkspaceWithStatus)` where the internal `workspace_path(workspace.id).try_into()` conversion fails; practically this happens only if `workspace_path` is changed to emit a string that is not a valid RFC 6901 JSON Pointer (e.g. no leading slash or an unescaped `/`/`~` in the segment).","commonSituations":"Developers hit this after refactoring `workspace_path` or `escape_pointer_segment` (e.g. removing the leading `/`, dropping the escaping, or using a raw workspace name instead of a UUID in the pointer). It is not triggered by workspace data or environment — it is a code-invariant assertion.","solutions":["Verify `workspace_path` returns a string starting with `/` with a properly escaped segment: \"/workspaces/<escaped-uuid>\".","Ensure `escape_pointer_segment` is applied to any non-UUID segment (replace `~` with `~0` and `/` with `~1`).","If a custom path was introduced, validate it with `Pointer::try_from(...)` and handle the error instead of `.expect()`.","Run the crate's unit tests for `workspace_patch::add` to confirm the path round-trips through json_patch."],"exampleFix":"// before\npath: workspace_path(workspace.id)\n    .try_into()\n    .expect(\"Workspace path should be valid\"),\n// after\nlet path = workspace_path(workspace.id);\nlet path: json_patch::Pointer = path.try_into().unwrap_or_else(|e| {\n    panic!(\"invalid JSON pointer {:?}: {}\", path, e)\n});\n// (or fix workspace_path to always emit \"/workspaces/<escaped-id>\")","handlingStrategy":"validation","validationCode":"fn is_valid_workspace_pointer(id: uuid::Uuid) -> bool {\n    let p = format!(\"/workspaces/{}\", id);\n    json_patch::Pointer::try_from(p).is_ok()\n}\n// assert before building the patch:\nassert!(is_valid_workspace_pointer(workspace.id));","typeGuard":"fn valid_pointer(s: &str) -> Option<json_patch::Pointer> {\n    json_patch::Pointer::try_from(s.to_string()).ok()\n}","tryCatchPattern":null,"preventionTips":["Never interpolate unescaped `/` or `~` into JSON Pointer segments.","Always run segments through escape_pointer_segment (~0/~1 escaping).","Add a unit test asserting the pointer converts via Pointer::try_from.","Treat .expect() on path building as a code invariant, not runtime error handling."],"tags":["rust","json-patch","panic","invariant-violation"],"backgroundTag":"invalid-json-pointer","analyzedSha":"4deb7eca8f381f7cbc1f9d15515a9ab8f8009053","analyzedAt":"2026-08-29T09:24:13.446Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}