From 2dae043e8ffcb030699f3523568544676e370b53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?cel=20=F0=9F=8C=B8?= Date: Fri, 29 Nov 2024 02:10:19 +0000 Subject: [PATCH] add some tracing --- Cargo.lock | 38 ++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + src/element.rs | 17 +++++++++++++++-- src/error.rs | 1 + src/reader.rs | 5 ++++- src/writer.rs | 1 + 6 files changed, 60 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 134cdc3..e2e0fd3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -256,6 +256,12 @@ version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a5b3dd1c072ee7963717671d1ca129f1048fda25edea6b752bfc71ac8854170" +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + [[package]] name = "parking_lot" version = "0.12.3" @@ -288,6 +294,7 @@ dependencies = [ "futures", "nom", "tokio", + "tracing", ] [[package]] @@ -416,6 +423,37 @@ dependencies = [ "syn", ] +[[package]] +name = "tracing" +version = "0.1.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c" +dependencies = [ + "once_cell", +] + [[package]] name = "unicode-ident" version = "1.0.12" diff --git a/Cargo.toml b/Cargo.toml index 3cb7177..c630152 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,3 +11,4 @@ circular = { version = "0.3.0", path = "../circular" } futures = "0.3.30" nom = "7.1.3" tokio = { version = "1.36.0", features = ["io-util", "net", "io-std", "full"] } +tracing = "0.1.41" diff --git a/src/element.rs b/src/element.rs index 98a3315..1f78419 100644 --- a/src/element.rs +++ b/src/element.rs @@ -8,6 +8,8 @@ use std::{ str::FromStr, }; +use tracing::debug; + use crate::{ error::{DeserializeError, Error}, xml::{self, parsers_complete::Parser, Attribute}, @@ -322,17 +324,28 @@ impl Element { let mut children = Vec::new(); loop { let child = self.content.front(); + debug!("child: {:?}", child); if let Some(child) = child { match child { Content::Element(element) => { if let Ok(child) = ::from_element(element.clone()) { + debug!("parsed child"); children.push(child); self.content.pop_front(); + } else { + debug!("failed to parse child"); + return Ok(children); } } Content::Text(_) => return Ok(children), - Content::PI => {} - Content::Comment(_) => {} + Content::PI => { + self.content.pop_front(); + continue; + } + Content::Comment(_) => { + self.content.pop_front(); + continue; + } } } else { return Ok(children); diff --git a/src/error.rs b/src/error.rs index dd8ea17..0cac59b 100644 --- a/src/error.rs +++ b/src/error.rs @@ -14,6 +14,7 @@ pub enum DeserializeError { FromStr(String), UnexpectedAttributes(HashMap), UnexpectedContent(VecDeque), + UnexpectedElement(Element), MissingAttribute(Name), IncorrectName(String), IncorrectNamespace(String), diff --git a/src/reader.rs b/src/reader.rs index aa4d467..d2de170 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -9,6 +9,7 @@ use std::{ str::{self, FromStr}, }; use tokio::io::{AsyncBufRead, AsyncBufReadExt, AsyncRead, AsyncReadExt}; +use tracing::debug; use crate::{ declaration::{Declaration, VersionInfo}, @@ -21,6 +22,7 @@ use crate::{ static MAX_STANZA_SIZE: usize = 65536; /// streaming reader that tracks depth and available namespaces at current depth +#[derive(Debug)] pub struct Reader { inner: R, pub buffer: Buffer, @@ -59,7 +61,7 @@ impl Reader where R: AsyncRead + Unpin, { - async fn read_buf<'s>(&mut self) -> Result { + pub async fn read_buf<'s>(&mut self) -> Result { Ok(self.inner.read_buf(&mut self.buffer).await?) } @@ -107,6 +109,7 @@ where pub async fn read<'s, T: FromElement>(&'s mut self) -> Result { let element = self.read_element().await?; + debug!("read element: {:?}", element); Ok(FromElement::from_element(element)?) } diff --git a/src/writer.rs b/src/writer.rs index 8b45869..25e19fb 100644 --- a/src/writer.rs +++ b/src/writer.rs @@ -13,6 +13,7 @@ use crate::{ }; // pub struct Writer { +#[derive(Debug)] pub struct Writer { inner: W, depth: Vec,