Skip to content

Document Result<T, Err> usage with #[pg_extern], or panic as a preferred method #1535

Open
@nyurik

Description

@nyurik

In Rust, panics tend to be 2nd class as they may result in various lock poisoning, slower perf, etc. Yet, it seems #[pg_extern] expects most functions to be returning the actual value rather than a Result<T, E>. I tried to look for any documentation, and saw a few examples like this one where the error type is Box<dyn std::error::Error + Send + Sync + 'static>. What is best approach to errors, and where can this be documented?

#[pg_extern]
fn result_table() -> Result<
    Option<::pgrx::iter::TableIterator<'static, (name!(a, Option<i32>), name!(b, Option<i32>))>>,
    Box<dyn std::error::Error + Send + Sync + 'static>,
> {
    Ok(Some(TableIterator::new(vec![(Some(1), Some(2))])))
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsImprovements or additions to documentationerror-handling

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions