|
1 | 1 | //! Helper for simpler error handling. |
2 | 2 | use datafusion_common::DataFusionError; |
| 3 | +use wasmtime_wasi::p2::FsError; |
3 | 4 |
|
4 | 5 | /// Extension for [`wasmtime::Error`]. |
5 | 6 | pub(crate) trait WasmToDataFusionErrorExt { |
|
74 | 75 | self.map_err(|e| e.into().context(description)) |
75 | 76 | } |
76 | 77 | } |
| 78 | + |
| 79 | +/// Failed allocation error. |
| 80 | +#[derive(Debug, Clone)] |
| 81 | +#[expect(missing_copy_implementations, reason = "allow later extensions")] |
| 82 | +pub struct LimitExceeded { |
| 83 | + /// Name of the allocation type/resource. |
| 84 | + pub(crate) name: &'static str, |
| 85 | + |
| 86 | + /// Allocation limit. |
| 87 | + pub(crate) limit: u64, |
| 88 | + |
| 89 | + /// Current allocation size. |
| 90 | + pub(crate) current: u64, |
| 91 | + |
| 92 | + /// Requested/additional allocation. |
| 93 | + pub(crate) requested: u64, |
| 94 | +} |
| 95 | + |
| 96 | +impl std::fmt::Display for LimitExceeded { |
| 97 | + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 98 | + let Self { |
| 99 | + name, |
| 100 | + limit, |
| 101 | + current, |
| 102 | + requested, |
| 103 | + } = self; |
| 104 | + |
| 105 | + write!( |
| 106 | + f, |
| 107 | + "{name} limit reached: limit<={limit} current=={current} requested+={requested}" |
| 108 | + ) |
| 109 | + } |
| 110 | +} |
| 111 | + |
| 112 | +impl std::error::Error for LimitExceeded {} |
| 113 | + |
| 114 | +impl From<LimitExceeded> for std::io::Error { |
| 115 | + fn from(e: LimitExceeded) -> Self { |
| 116 | + Self::new(std::io::ErrorKind::QuotaExceeded, e.to_string()) |
| 117 | + } |
| 118 | +} |
| 119 | + |
| 120 | +impl From<LimitExceeded> for FsError { |
| 121 | + fn from(e: LimitExceeded) -> Self { |
| 122 | + let e: std::io::Error = e.into(); |
| 123 | + e.into() |
| 124 | + } |
| 125 | +} |
0 commit comments