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

impl Display for Receipt #901

Merged
merged 8 commits into from
Feb 18, 2025
Merged

impl Display for Receipt #901

merged 8 commits into from
Feb 18, 2025

Conversation

rafal-ch
Copy link
Contributor

@rafal-ch rafal-ch commented Jan 21, 2025

This PR implements Display for Receipt for easier logging.

Once this is merged and released, there will be a follow-up PR to the fuel-core to get rid of this boilerplate.

Follow-up PR: FuelLabs/fuel-core#2616

Checklist

  • Breaking changes are clearly marked as such in the PR description and changelog
  • New behavior is reflected in tests
  • If performance characteristic of an instruction change, update gas costs as well or make a follow-up PR for that
  • The specification matches the implemented behavior (link update PR if changes are needed)

Before requesting review

  • I have reviewed the code myself

@@ -156,6 +156,51 @@ pub enum Receipt {
},
}

impl core::fmt::Display for Receipt {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why can't we derive the implementation with all fields?=D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Regarding all fields - I thought it may be just a bit too much details, which, when needed, could be retrieved by Debug. I prefer Display to be more concise, targeted on humans, not developers :)

I have no strong opinions here, so if you prefer to have all fields, I can just stick derive_more::Display without any custom #[display(fmt = attributes.

Let me know what you think.

@rafal-ch rafal-ch self-assigned this Feb 11, 2025
Receipt::Call { id, .. } => write!(f, "Call({})", id),
Receipt::Return { id, .. } => write!(f, "Return({})", id),
Receipt::ReturnData { id, .. } => write!(f, "ReturnData({})", id),
Receipt::Panic { id, .. } => write!(f, "Panic({})", id),
Copy link
Member

Choose a reason for hiding this comment

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

do you think we can display the panic reason in a meaningful way?

reason: PanicInstruction,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, since PanicReason is a simple repr(u8) enum, we can just debug-print it to get an output like:

Panic(id=0000000000000000000000000000000000000000000000000000000000000000, reason=OutOfGas)

Updated in 7e04606

Copy link
Member

Choose a reason for hiding this comment

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

nice, ty

@rafal-ch rafal-ch marked this pull request as ready for review February 18, 2025 11:43
@rafal-ch rafal-ch requested a review from a team February 18, 2025 12:17
@xgreenx xgreenx enabled auto-merge February 18, 2025 19:08
@xgreenx xgreenx added this pull request to the merge queue Feb 18, 2025
Merged via the queue into master with commit f8fe20c Feb 18, 2025
39 checks passed
@xgreenx xgreenx deleted the rafal/display_on_recepits branch February 18, 2025 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants