pub mod embedding;
pub mod engine;
#[cfg(any(test, feature = "test-support"))]
pub mod fake_store;
pub(crate) mod projections;
pub mod storage;
pub mod store;
const LOGGED_MAX_CHARS: usize = 512;
pub(crate) fn logged(error: &dyn std::fmt::Display) -> String {
let text = error.to_string();
let mut out = String::with_capacity(text.len().min(LOGGED_MAX_CHARS) + 16);
for (taken, c) in text.chars().enumerate() {
if taken == LOGGED_MAX_CHARS {
out.push_str(" [truncated]");
break;
}
if c.is_control() {
out.extend(c.escape_default());
} else {
out.push(c);
}
}
out
}
#[cfg(test)]
mod logged_tests {
use super::{LOGGED_MAX_CHARS, logged};
#[test]
fn control_characters_are_escaped() {
let text = logged(&"relation \"kb\" does not exist\nERROR forged line");
assert!(!text.contains('\n'), "{text}");
assert!(text.contains("\\n"), "{text}");
}
#[test]
fn long_text_is_bounded() {
let text = logged(&"x".repeat(LOGGED_MAX_CHARS * 4));
assert!(
text.chars().count() < LOGGED_MAX_CHARS + 20,
"{}",
text.len()
);
assert!(text.ends_with("[truncated]"), "{text}");
}
}