-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Use SharedError
for body streaming
#4392
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
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 11 Ignored Deployments
|
✅ This changes can build |
🟢 CI successful 🟢Thanks |
impl Serialize for SharedError { | ||
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> { | ||
let mut v = vec![self.to_string()]; | ||
let mut source = self.source(); | ||
while let Some(s) = source { | ||
v.push(s.to_string()); | ||
source = s.source(); | ||
} | ||
Serialize::serialize(&v, serializer) | ||
} | ||
} | ||
|
||
impl<'de> Deserialize<'de> for SharedError { | ||
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> { | ||
use serde::de::Error; | ||
let mut messages = <Vec<String>>::deserialize(deserializer)?; | ||
let mut e = match messages.pop() { | ||
Some(e) => anyhow!(e), | ||
None => return Err(Error::custom("expected at least 1 error message")), | ||
}; | ||
while let Some(message) = messages.pop() { | ||
e = e.context(message); | ||
} | ||
Ok(SharedError::new(e)) | ||
} | ||
} |
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.
Not sure if this is a good idea. It's not perfectly restoring error types. Maybe we should return an Serialization error when there is an non-anyhow error in the chain.
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.
Does it matter? The first value is guaranteed to be an anyhow::Error
, and the sources are only guaranteed to be dyn std::error::Error
implementors. I'm not sure how to even observe that the real struct changes between serialization and deserialization.
Pending vercel/turborepo#4392 landing in Turbopack (and #47476 landing here), this removes `BodyError` and switches to `SharedError`. That should allow us to preserve the source chain of errors for when we finally display it to the dev, aiding debugging.
Follow up to vercel/turborepo#4329, this removes `BodyError` (which was just a simple `String` and not an `Error`) and switches to `SharedError`. I've implemented a basic `PartialEq` and `Serialization` for `SharedError` so that it doesn't infect everything that uses `Body`.
Follow up to vercel/turborepo#4329, this removes `BodyError` (which was just a simple `String` and not an `Error`) and switches to `SharedError`. I've implemented a basic `PartialEq` and `Serialization` for `SharedError` so that it doesn't infect everything that uses `Body`.
Follow up to vercel/turborepo#4329, this removes `BodyError` (which was just a simple `String` and not an `Error`) and switches to `SharedError`. I've implemented a basic `PartialEq` and `Serialization` for `SharedError` so that it doesn't infect everything that uses `Body`.
Follow up to #4329, this removes
BodyError
(which was just a simpleString
and not anError
) and switches toSharedError
.I've implemented a basic
PartialEq
andSerialization
forSharedError
so that it doesn't infect everything that usesBody
.