fix: fall back to the default when a servarr returns an unknown enum value
A Servarr build can emit an enum value this app has no name for, either as a string it does not recognise or as a bare integer for a value the build itself cannot name. Until now any such value in a response failed the whole payload, so one unexpected artist status, download status, task name, series type, minimum availability, credit type, or security setting emptied the entire view with "Failed to parse response!". Every enum-typed field on a struct the app only ever deserializes and displays now uses from_json_or_default, so an unrecognised value degrades to that enum's default and the rest of the record is kept. Known values still map exactly as before and serialization is untouched. Fields on request bodies (Add*Body, Add*Options, Edit*Params, the root folder bodies) are deliberately left alone: those structs are only ever serialized, so the attribute would be meaningless there. No candidate struct is round-tripped: every edit and toggle in the app re-fetches the raw JSON value and patches it by key, so the fallback can never be written back to a server as a real setting. The one Option field, the security config's authentication_required, also carries serde(default), because deserialize_with on an Option turns a missing key into a hard error. An unknown value there yields None. Verified by mutation. Removing the attribute from one field per tree fails exactly that field's test and nothing else. Dropping default from the Option field fails only the missing-key test with "missing field authenticationRequired"; dropping deserialize_with from it fails only the unknown-value test. All 21 new fallback tests fail against the unguarded code with "invalid type: integer 2, expected string or map".
This commit is contained in:
10 files changed
+529
-6
No files matched your search
@@ -112,6 +112,7 @@ pub struct DeleteSeriesParams {
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct DownloadRecord {
|
||||
pub title: String,
|
||||
#[serde(deserialize_with = "super::from_json_or_default")]
|
||||
pub status: DownloadStatus,
|
||||
#[serde(deserialize_with = "super::from_i64")]
|
||||
pub id: i64,
|
||||
@@ -314,12 +315,14 @@ pub struct Series {
|
||||
#[serde(deserialize_with = "super::from_i64")]
|
||||
pub year: i64,
|
||||
pub monitored: bool,
|
||||
#[serde(deserialize_with = "super::from_json_or_default")]
|
||||
pub series_type: SeriesType,
|
||||
pub path: String,
|
||||
pub genres: Vec<String>,
|
||||
pub tags: Vec<Number>,
|
||||
pub ratings: Rating,
|
||||
pub ended: bool,
|
||||
#[serde(deserialize_with = "super::from_json_or_default")]
|
||||
pub status: SeriesStatus,
|
||||
pub overview: Option<String>,
|
||||
pub network: Option<String>,
|
||||
@@ -556,6 +559,7 @@ pub struct SonarrReleaseDownloadBody {
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SonarrTask {
|
||||
pub name: String,
|
||||
#[serde(deserialize_with = "super::from_json_or_default")]
|
||||
pub task_name: SonarrTaskName,
|
||||
#[serde(deserialize_with = "super::from_i64")]
|
||||
pub interval: i64,
|
||||
|
||||
Reference in new issue
Block a user