stanzastream: handle malformed stanzas more gracefully

This introduces the FallibleStreamElement type which, instead of
failing parsing altogether, captures certain types of parse errors and
allows the user (in this case, the stanzastream) to react to these
errors appropriately.

This allows us to drop invalid stanzas (e.g. with malformed values in
strictly-checked fields) instead of failing the entire stream.

Fixes #172.
This commit is contained in:
Jonas Schäfer 2026-06-06 13:55:27 +02:00
commit cc92d113fa
11 changed files with 401 additions and 31 deletions

View file

@ -55,7 +55,11 @@ pub async fn auth<S: AsyncBufRead + AsyncWrite + Unpin>(
.await?;
loop {
match stream.next().await {
match stream
.next()
.await
.map(|v| v.map(|v| v.into_read_error()).flatten())
{
Some(Ok(XmppStreamElement::Sasl(sasl))) => match sasl {
Nonza::Challenge(challenge) => {
let response = mechanism