Run `f` inside [`panic::catch_unwind`], logging and swallowing any panic. Returns `Some(value)` on success and `None` on panic. The error message includes `label` (the operation name, e.g. `"hover"` or `"goto_definition"`), `uri`, and the optional cursor `position`. This centralises the boilerplate that every LSP handler uses to guard against stack overflows and unexpected panics in the resolut
(
label: &str,
uri: &str,
position: Option<Position>,
f: impl FnOnce() -> T + UnwindSafe,
)
| 132 | /// }); |
| 133 | /// ``` |
| 134 | pub(crate) fn catch_panic<T>( |
| 135 | label: &str, |
| 136 | uri: &str, |
| 137 | position: Option<Position>, |
| 138 | f: impl FnOnce() -> T + UnwindSafe, |
| 139 | ) -> Option<T> { |
| 140 | match panic::catch_unwind(f) { |
| 141 | Ok(value) => Some(value), |
| 142 | Err(_) => { |
| 143 | if let Some(pos) = position { |
| 144 | tracing::error!( |
| 145 | "PHPantom: panic during {} at {}:{}:{}", |
| 146 | label, |
| 147 | uri, |
| 148 | pos.line, |
| 149 | pos.character |
| 150 | ); |
| 151 | } else { |
| 152 | tracing::error!("PHPantom: panic during {} at {}", label, uri); |
| 153 | } |
| 154 | None |
| 155 | } |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | /// Convenience wrapper around [`catch_panic`] for closures that |
| 160 | /// capture `&self` or other non-[`UnwindSafe`] references. |
no outgoing calls
no test coverage detected