vmm: use Error trait directly with Note for compiler bug

While working on this, I found a subtle but severe compiler bug [0].
To fight the bug with explicitness rather than implicitness (to
prevent weird stuff in the future), this change is beneficial.

The bug is at least in Rust stable 1.34..1.87.

[0]: https://github.com/rust-lang/rust/issues/141673

Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
On-behalf-of: SAP philipp.schuster@sap.com
This commit is contained in:
Philipp Schuster 2025-05-28 13:01:55 +02:00 committed by Rob Bradford
parent 060c9de07f
commit 6ea132708c

View file

@ -1,12 +1,13 @@
// Copyright © 2025 Cyberus Technology GmbH
//
// SPDX-License-Identifier: Apache-2.0
//
use std::error::Error;
/// Prints a chain of errors to the user in a consistent manner.
/// The user will see a clear chain of errors, followed by debug output
/// for opening issues.
pub fn cli_print_error_chain(top_error: &dyn std::error::Error, component: &str) {
pub fn cli_print_error_chain(top_error: &dyn Error, component: &str) {
eprint!("Error: {component} exited with the following ");
if top_error.source().is_none() {
eprintln!("error:");
@ -14,7 +15,9 @@ pub fn cli_print_error_chain(top_error: &dyn std::error::Error, component: &str)
} else {
eprintln!("chain of errors:");
std::iter::successors(Some(top_error), |sub_error| {
sub_error.source()
// Dereference necessary to mitigate rustc compiler bug.
// See <https://github.com/rust-lang/rust/issues/141673>
(*sub_error).source()
})
.enumerate()
.for_each(|(level, error)| {