Skip to content

Commit

Permalink
fix(baseline): support invalid baseline json
Browse files Browse the repository at this point in the history
  • Loading branch information
fiji-flo committed Dec 13, 2024
1 parent f5600cd commit bde35ee
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/rari-data/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ url.workspace = true
chrono.workspace = true
indexmap.workspace = true
schemars.workspace = true
tracing.workspace = true
26 changes: 24 additions & 2 deletions crates/rari-data/src/baseline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,45 @@ use std::fmt;
use std::marker::PhantomData;
use std::path::Path;

use indexmap::IndexMap;
use rari_utils::io::read_to_string;
use schemars::JsonSchema;
use serde::de::{self, value, SeqAccess, Visitor};
use serde::{Deserialize, Deserializer, Serialize};
use serde_json::Value;
use url::Url;

use crate::error::Error;

#[derive(Deserialize, Serialize, Clone, Debug)]
pub struct WebFeatures {
pub features: BTreeMap<String, FeatureData>,
pub features: IndexMap<String, FeatureData>,
}

#[derive(Deserialize, Serialize, Clone, Debug)]
pub struct DirtyWebFeatures {
pub features: IndexMap<String, Value>,
}

impl WebFeatures {
pub fn from_file(path: &Path) -> Result<Self, Error> {
let json_str = read_to_string(path)?;
Ok(serde_json::from_str(&json_str)?)
let dirty_map: DirtyWebFeatures = serde_json::from_str(&json_str)?;
let map = WebFeatures {
features: dirty_map
.features
.into_iter()
.filter_map(|(k, v)| {
serde_json::from_value::<FeatureData>(v)
.inspect_err(|e| {
tracing::error!("Error serializing baseline for {}: {}", k, &e)
})
.ok()
.map(|v| (k, v))
})
.collect(),
};
Ok(map)
}

pub fn feature_status(&self, bcd_key: &str) -> Option<&SupportStatusWithByKey> {
Expand Down

0 comments on commit bde35ee

Please sign in to comment.