-
Notifications
You must be signed in to change notification settings - Fork 565
treewide: streamline #[source] and Error #7069
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
Conversation
|
I think my recent rebase messed up a few things and now the CI fails. Looking again into this soon, no later than Monday. Happy weekend! |
a53ee9d to
aa11770
Compare
|
I think the failing ARM64 test is flaky and unrelated, but I'm not sure @rbradford |
| /// Failed to create kill eventfd. | ||
| CreateKillEventFd(io::Error), | ||
| #[error("Failed to create kill eventfd: {0}")] | ||
| CreateKillEventFd(#[source] io::Error), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everywhere the #[error] macro is added, we end up with duplicate documentation strings. I think this happened for other enums previously that already duplicate this. I could not spot any pattern for when there is additional documentation for the enum members. Does this make a difference for the generated documentation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's duplicated. Not a fan but currently, I don't see a long hanging fruit to solve this.
Using a smart combination of a few IDE shortcuts, the creation of this PR was thankfully quite easy and I'm quite confident the copy and paste error rate is close to zero.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you are going for a tree-wide cleanup, this one-liner removes the clear duplicates on your PR branch:
(requires GNU sed for the -z multi line matching)
$ git ls-files | grep .rs | xargs -n 10 sed -z -i 's_\([[:space:]]*\)/// \(.*\)\.\n\1#\[error("\2_\1#\[error("\2_g'Leads to:
$ git diff --stat
arch/src/aarch64/fdt.rs | 1 -
arch/src/aarch64/mod.rs | 4 ----
arch/src/aarch64/uefi.rs | 3 ---
arch/src/riscv64/fdt.rs | 1 -
arch/src/riscv64/mod.rs | 4 ----
arch/src/x86_64/mod.rs | 3 ---
arch/src/x86_64/mptable.rs | 10 ----------
arch/src/x86_64/regs.rs | 12 ------------
arch/src/x86_64/smbios.rs | 2 --
block/src/async_io.rs | 5 -----
devices/src/interrupt_controller.rs | 12 ------------
pci/src/bus.rs | 7 -------
pci/src/device.rs | 5 -----
pci/src/msix.rs | 2 --
vhost_user_block/src/lib.rs | 2 --
vhost_user_net/src/lib.rs | 9 ---------
virtio-devices/src/vsock/unix/mod.rs | 10 ----------
vm-device/src/bus.rs | 3 ---
vmm/src/device_manager.rs | 47 -----------------------------------------------
vmm/src/memory_manager.rs | 16 ----------------
20 files changed, 158 deletions(-)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I checked the generated documentation and the #[error(...)] implementation isn't easily visible. So keeping the duplicate info for the doc where it exists may be the better option than just having the enum member name show up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There might be some derive macro magic streamlining the Display::fmt() impl and the doc comments, but let's stick to the duplication for now. I think having doc comments at all is much better.
Also as doc comment and the display repr as close by, it is easy to keep them in sync
This streamlines the code base to follow best practices for error handling in Rust: Each error struct implements std::error::Error (most due via thiserror::Error derive macro) and sets its source accordingly. This allows future work that nicely prints the error chains, for example. So far, the convention is that each error prints its sub error as part of its Display::fmt() impl. Signed-off-by: Philipp Schuster <[email protected]> On-behalf-of: SAP [email protected]
This streamlines the code base to follow best practices for error handling in Rust: Each error struct implements std::error::Error (most due via thiserror::Error derive macro) and sets its source accordingly. This allows future work that nicely prints the error chains, for example. So far, the convention is that each error prints its sub error as part of its Display::fmt() impl. Signed-off-by: Philipp Schuster <[email protected]> On-behalf-of: SAP [email protected]
This streamlines the code base to follow best practices for error handling in Rust: Each error struct implements std::error::Error (most due via thiserror::Error derive macro) and sets its source accordingly. This allows future work that nicely prints the error chains, for example. So far, the convention is that each error prints its sub error as part of its Display::fmt() impl. Signed-off-by: Philipp Schuster <[email protected]> On-behalf-of: SAP [email protected]
This streamlines the code base to follow best practices for error handling in Rust: Each error struct implements std::error::Error (most due via thiserror::Error derive macro) and sets its source accordingly. This allows future work that nicely prints the error chains, for example. So far, the convention is that each error prints its sub error as part of its Display::fmt() impl. Signed-off-by: Philipp Schuster <[email protected]> On-behalf-of: SAP [email protected]
This streamlines the code base to follow best practices for error handling in Rust: Each error struct implements std::error::Error (most due via thiserror::Error derive macro) and sets its source accordingly. This allows future work that nicely prints the error chains, for example. So far, the convention is that each error prints its sub error as part of its Display::fmt() impl. Signed-off-by: Philipp Schuster <[email protected]> On-behalf-of: SAP [email protected]
This streamlines the code base to follow best practices for error handling in Rust: Each error struct implements std::error::Error (most due via thiserror::Error derive macro) and sets its source accordingly. This allows future work that nicely prints the error chains, for example. So far, the convention is that each error prints its sub error as part of its Display::fmt() impl. Signed-off-by: Philipp Schuster <[email protected]> On-behalf-of: SAP [email protected]
This streamlines the code base to follow best practices for error handling in Rust: Each error struct implements std::error::Error (most due via thiserror::Error derive macro) and sets its source accordingly. This allows future work that nicely prints the error chains, for example. So far, the convention is that each error prints its sub error as part of its Display::fmt() impl. Signed-off-by: Philipp Schuster <[email protected]> On-behalf-of: SAP [email protected]
This streamlines the code base to follow best practices for error handling in Rust: Each error struct implements std::error::Error (most due via thiserror::Error derive macro) and sets its source accordingly. This allows future work that nicely prints the error chains, for example. So far, the convention is that each error prints its sub error as part of its Display::fmt() impl. Signed-off-by: Philipp Schuster <[email protected]> On-behalf-of: SAP [email protected]
This streamlines the code base to follow best practices for error handling in Rust: Each error struct implements std::error::Error (most due via thiserror::Error derive macro) and sets its source accordingly. This allows future work that nicely prints the error chains, for example. So far, the convention is that each error prints its sub error as part of its Display::fmt() impl. Signed-off-by: Philipp Schuster <[email protected]> On-behalf-of: SAP [email protected]
This streamlines the code base to follow best practices for error handling in Rust: Each error struct implements std::error::Error (most due via thiserror::Error derive macro) and sets its source accordingly. This allows future work that nicely prints the error chains, for example. So far, the convention is that each error prints its sub error as part of its Display::fmt() impl. Signed-off-by: Philipp Schuster <[email protected]> On-behalf-of: SAP [email protected]
This streamlines the code base to follow best practices for error handling in Rust: Each error struct implements std::error::Error (most due via thiserror::Error derive macro) and sets its source accordingly. This allows future work that nicely prints the error chains, for example. So far, the convention is that each error prints its sub error as part of its Display::fmt() impl. Signed-off-by: Philipp Schuster <[email protected]> On-behalf-of: SAP [email protected]
This streamlines the code base to follow best practices for error handling in Rust: Each error struct implements std::error::Error (most due via thiserror::Error derive macro) and sets its source accordingly. This allows future work that nicely prints the error chains, for example. So far, the convention is that each error prints its sub error as part of its Display::fmt() impl. Signed-off-by: Philipp Schuster <[email protected]> On-behalf-of: SAP [email protected]
This streamlines the code base to follow best practices for error handling in Rust: Each error struct implements std::error::Error (most due via thiserror::Error derive macro) and sets its source accordingly. This allows future work that nicely prints the error chains, for example. So far, the convention is that each error prints its sub error as part of its Display::fmt() impl. Signed-off-by: Philipp Schuster <[email protected]> On-behalf-of: SAP [email protected]
This streamlines the code base to follow best practices for error handling in Rust: Each error struct implements std::error::Error (most due via thiserror::Error derive macro) and sets its source accordingly. This allows future work that nicely prints the error chains, for example. So far, the convention is that each error prints its sub error as part of its Display::fmt() impl. Signed-off-by: Philipp Schuster <[email protected]> On-behalf-of: SAP [email protected]
This streamlines the code base to follow best practices for error handling in Rust: Each error struct implements std::error::Error (most due via thiserror::Error derive macro) and sets its source accordingly. This allows future work that nicely prints the error chains, for example. So far, the convention is that each error prints its sub error as part of its Display::fmt() impl. Signed-off-by: Philipp Schuster <[email protected]> On-behalf-of: SAP [email protected]
This streamlines the code base to follow best practices for error handling in Rust: Each error struct implements std::error::Error (most due via thiserror::Error derive macro) and sets its source accordingly. This allows future work that nicely prints the error chains, for example. So far, the convention is that each error prints its sub error as part of its Display::fmt() impl. Signed-off-by: Philipp Schuster <[email protected]> On-behalf-of: SAP [email protected]
|
I rebased this. Are we good to go, here? @rbradford I know the changes are a lot and hard to review! |
Follow-up of #7061 and split-out from #7066.
This MR implements
std::error::Errorvia thethiserror::Errorderive macro for all error types where this wasn't done yet. Also#[source]is set properly everywhere. This will allow #7066 eventually.This still follows the "current" style for errors that
Display::fmt()includes any suberror like this": {0}"Steps to Undraft