Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions crates/prism/src/outbound/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ pub async fn connect_addr(
let started = Instant::now();
trace!(target_addr = %target_addr, "[CONNECT/OUTBOUND] starting upstream connection");

let connect_timeout =
Duration::from_millis(config.network.socket.upstream_connect_timeout_ms);
let connect_timeout = Duration::from_millis(config.network.socket.upstream_connect_timeout_ms);
match timeout(connect_timeout, try_connect(target_addr, config)).await {
Ok(result) => result,
Err(_) => {
Expand Down
8 changes: 6 additions & 2 deletions src/config/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ impl ConfigLoader {
}

fn load_from_str_inner(content: &str, path: &Path) -> Result<NecronPrismConfig> {
eprintln!("DEBUG: load_from_str_inner called with content:\n{}", content);
eprintln!(
"DEBUG: load_from_str_inner called with content:\n{}",
content
);
// Parse as generic TOML table first to avoid serde(flatten) issues
let table: toml::Table = content.parse()
let table: toml::Table = content
.parse()
.with_context(|| format!("failed to parse TOML config {}", path.display()))?;
eprintln!("DEBUG: parsed table: {:?}", table);

Expand Down
22 changes: 11 additions & 11 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl Serialize for NecronPrismConfig {
{
use serde::ser::SerializeMap;
let mut map = serializer.serialize_map(None)?;

// Serialize prism fields at top level (flatten)
if let Ok(value) = toml::Value::try_from(&self.prism) {
if let toml::Value::Table(table) = value {
Expand All @@ -82,10 +82,10 @@ impl Serialize for NecronPrismConfig {
}
}
}

// Serialize api as a nested table
map.serialize_entry("api", &self.api)?;

map.end()
}
}
Expand All @@ -96,23 +96,23 @@ impl<'de> Deserialize<'de> for NecronPrismConfig {
D: serde::Deserializer<'de>,
{
use serde::de::MapAccess;

struct NecronPrismConfigVisitor;

impl<'de> serde::de::Visitor<'de> for NecronPrismConfigVisitor {
type Value = NecronPrismConfig;

fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
formatter.write_str("a TOML table")
}

fn visit_map<M>(self, mut map: M) -> std::result::Result<NecronPrismConfig, M::Error>
where
M: MapAccess<'de>,
{
let mut api: Option<ApiConfig> = None;
let mut prism_fields = toml::map::Map::new();

while let Some(key) = map.next_key::<String>()? {
if key == "api" {
api = Some(map.next_value()?);
Expand All @@ -121,19 +121,19 @@ impl<'de> Deserialize<'de> for NecronPrismConfig {
prism_fields.insert(key, value);
}
}

// Use toml::Value as a serde deserializer directly
let prism_value = toml::Value::Table(prism_fields);
let prism = Config::deserialize(prism_value.into_deserializer())
.map_err(serde::de::Error::custom)?;

Ok(NecronPrismConfig {
prism,
api: api.unwrap_or_default(),
})
}
}

deserializer.deserialize_map(NecronPrismConfigVisitor)
}
}
Expand Down