Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename ErrorReportable::report() to unwrap_or_report() #1568

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pgrx-pg-sys/src/submodules/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub trait ErrorReportable {
type Inner;

/// Raise a Postgres ERROR if appropriate, otherwise return a value
fn report(self) -> Self::Inner;
fn unwrap_or_report(self) -> Self::Inner;
}

impl<T, E> ErrorReportable for Result<T, E>
Expand All @@ -42,7 +42,7 @@ where
/// If this [`Result`] represents the `Err` variant, raise it as an error. If it happens to
/// be an [`ErrorReport`], then that is specifically raised. Otherwise it's just a general
/// [`ereport!`] as a [`PgLogLevel::ERROR`].
fn report(self) -> Self::Inner {
fn unwrap_or_report(self) -> Self::Inner {
self.unwrap_or_else(|e| {
let any: Box<&dyn Any> = Box::new(&e);
if any.downcast_ref::<ErrorReport>().is_some() {
Expand Down Expand Up @@ -235,7 +235,7 @@ impl ErrorReportWithLevel {

impl ErrorReport {
/// Create an [ErrorReport] which can be raised via Rust's [std::panic::panic_any()] or as
/// a specific Postgres "ereport()` level via [ErrorReport::report(self, PgLogLevel)]
/// a specific Postgres "ereport()` level via [ErrorReport::unwrap_or_report(self, PgLogLevel)]
///
/// Embedded "file:line:col" location information is taken from the caller's location
#[track_caller]
Expand All @@ -251,7 +251,7 @@ impl ErrorReport {
}

/// Create an [ErrorReport] which can be raised via Rust's [std::panic::panic_any()] or as
/// a specific Postgres "ereport()` level via [ErrorReport::report(self, PgLogLevel)].
/// a specific Postgres "ereport()` level via [ErrorReport::unwrap_or_report(self, PgLogLevel)].
///
/// For internal use only
fn with_location<S: Into<String>>(
Expand Down
2 changes: 1 addition & 1 deletion pgrx-sql-entity-graph/src/pg_extern/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ impl PgExtern {
let mut ret_expr = quote! { #func_name(#(#arg_pats),*) };
if result {
// If it's a result, we need to report it.
ret_expr = quote! { #ret_expr.report() };
ret_expr = quote! { #ret_expr.unwrap_or_report() };
}
if !optional {
// If it's not already an option, we need to wrap it.
Expand Down
2 changes: 1 addition & 1 deletion pgrx/src/datum/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ where
/// [`ERRCODE_DATA_EXCEPTION`]: pg_sys::errcodes::PgSqlErrorCode::ERRCODE_DATA_EXCEPTION
#[inline]
fn into_datum(self) -> Option<pg_sys::Datum> {
self.report().into_datum()
self.unwrap_or_report().into_datum()
}

#[inline]
Expand Down
2 changes: 1 addition & 1 deletion pgrx/src/spi/tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ impl<'conn> Iterator for SpiTupleTable<'conn> {
None
} else {
assert!(self.current >= 0);
self.get_heap_tuple().report()
self.get_heap_tuple().unwrap_or_report()
}
}

Expand Down
Loading