Skip to main content

WarningCollector

Struct WarningCollector 

Source
pub struct WarningCollector { /* private fields */ }
Expand description

A thread-safe collector for ExtensionWarnings.

Extensions create a single WarningCollector (typically stored in their global or bind-data state) and call emit whenever a warning condition is detected. Warnings can later be surfaced through a table function (e.g., SELECT * FROM __extension_warnings()).

§Thread safety

WarningCollector uses a Mutex internally and is safe to share across threads via Arc<WarningCollector>. A panic on another thread while it held the lock does not lose warnings: every operation is a single Vec call, so the list is intact, and the collector keeps using it.

§Bounded

A collector keeps at most a limit of warnings between drains (DEFAULT_MAX_WARNINGS, 10,000, from new; any other with with_limit). Past it, emit does not store the warning but counts it in dropped, so a condition reported once per request or row cannot grow the list without bound in a long-lived process (2,000,000 warnings were 381 MB). The first warnings are the ones kept.

Behaviour change in 0.20.0: before it, every warning was stored, and a collector never drained grew for as long as the process lived.

Implementations§

Source§

impl WarningCollector

Source

pub const fn new() -> Self

Creates a new, empty WarningCollector that keeps at most DEFAULT_MAX_WARNINGS warnings between drains.

Warnings past the limit are counted (dropped), not stored.

Source

pub const fn with_limit(limit: usize) -> Self

Creates a collector that keeps at most limit warnings between drains.

Source

pub fn dropped(&self) -> u64

How many warnings were discarded because the collector already held its limit. drain and clear reset it.

Source

pub fn emit(&self, warning: ExtensionWarning)

Emits a warning, adding it to the collector, or counting it in dropped when the collector is full.

Source

pub fn len(&self) -> usize

Returns the number of warnings currently collected.

Source

pub fn is_empty(&self) -> bool

Returns true if no warnings have been collected.

Source

pub fn snapshot(&self) -> Vec<ExtensionWarning>

Returns a snapshot of all collected warnings without clearing them.

Source

pub fn drain(&self) -> Vec<ExtensionWarning>

Drains all collected warnings, returning them and leaving the collector empty.

Resets dropped: read it first to learn how many warnings the full collector discarded since the last drain.

Source

pub fn clear(&self)

Clears all collected warnings and resets dropped.

Trait Implementations§

Source§

impl Debug for WarningCollector

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for WarningCollector

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.