rust-lang-deprecated / failure

Error management

Home Page:https://rust-lang-nursery.github.io/failure/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Compat should override method source()

pchampin opened this issue · comments

Compat should override method source() to something like return self.cause().compat().
That way, the chain of causes of the Fail would be visible from code expecting the standard Error trait.

I've also noticed it „loses“ the sources when going through compat.

However, I think the problem is that it returns Option<&dyn Error>. That means, it can't create the Compat on stack and return it, it would have to contain it in itself, which it probably doesn't. It can't reference thin air :-(.

I'm still trying to think of a hacky way to work around this (somewhat in direction of making Compat #[repr(transparent)] and do some clever transmuting, but the dyns there seem to pose problems there; I'm not sure this would be worth it even if it worked).

Other option would be to create a Vec of some Compat-like structs that would wrap the &dyn Errors and return these and let them delegate. This would still be problematic because such thing would be effectively a self-referencing structure and it would make the top-level Compat a bit more expensive to create, but I'm confident this could be beaten long enough to actually make it work (also with unsafe, though). Again, I'm not sure if it's worth it.