Skip to content

Conversation

@RAprogramm
Copy link
Owner

Summary

  • allow explicit #[backtrace] on #[source]/#[from] fields when the type is an error and record whether the metadata was inferred or explicit to avoid duplicate provisioning
  • update generated Error::provide bodies to delegate requests to sources via a new internal ThiserrorProvide shim before exposing stored backtraces
  • expose the gated provide module for derived code, extend regression tests, and bump the crate versions/documentation

Testing

  • cargo +nightly fmt --
  • cargo clippy -- -D warnings
  • cargo build --all-targets
  • cargo test --all
  • cargo doc --no-deps
  • cargo deny check
  • cargo audit

https://chatgpt.com/codex/tasks/task_e_68cdfdc130f0832b888edbc0016e0f6d

@RAprogramm RAprogramm merged commit eb3d9c9 into new_version Sep 20, 2025
1 of 2 checks passed
@RAprogramm RAprogramm deleted the codex/extend-backtrace-field-type-validation branch September 20, 2025 01:40
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex Review: Here are some suggestions.

Reply with @codex fix comments to fix any unresolved comments.

About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".

Comment on lines +317 to +333
fn struct_provide_method(fields: &Fields) -> Option<TokenStream> {
let backtrace = fields.backtrace_field()?;
let field = backtrace.field();
let request = quote!(request);
let delegates_to_source =
matches!(backtrace.kind(), BacktraceFieldKind::Explicit) && !backtrace.stores_backtrace();
let mut statements = Vec::new();
let mut needs_trait_import = false;

if let Some(source_field) = fields.iter().find(|candidate| candidate.attrs.has_source()) {
needs_trait_import = true;
let member = &source_field.member;
statements.push(provide_source_tokens(
quote!(self.#member),
source_field,
&request
));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Delegate backtrace to the correct source field

The generated provide implementation always forwards the request to the first #[source] field, even when a different field is the one annotated with #[backtrace]. For a struct with multiple sources where only the second source carries the backtrace (e.g. an optional secondary source annotated with #[source] and #[backtrace]), std::error::request_ref::<std::backtrace::Backtrace> will never reach that secondary source because only the first source is delegated. Before this change the derive called Error::backtrace(self) and the backtrace from the annotated source was still provided, so this is a regression for multi-source errors.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants