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

Container writers panic if early return prevents close() #812

Open
zslayton opened this issue Aug 14, 2024 · 0 comments
Open

Container writers panic if early return prevents close() #812

zslayton opened this issue Aug 14, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@zslayton
Copy link
Contributor

The WriteAsIon impl for LazyValue and related types writes as it reads, which is fine for the happy path:

impl<'top, D: Decoder> WriteAsIon for LazyStruct<'top, D> {
fn write_as_ion<V: ValueWriter>(&self, writer: V) -> IonResult<()> {
let mut struct_writer = writer.struct_writer()?;
for field_result in self {
let field = field_result?;
struct_writer.write(field.name()?, field.value())?;
}
struct_writer.close()
}
}

However, notice that if reading fails, ? causes an early return. This leads to the struct_writer not getting closed; when the function returns, the struct_writer gets dropped and panics because it was not closed.

We need a way to "defuse" the struct_writer before returning an error.

@zslayton zslayton added the bug Something isn't working label Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant