Skip to content

Commit

Permalink
Handle configuration conversion failures explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
BLYKIM committed Dec 27, 2024
1 parent 6ddaa0b commit d398d76
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 21 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ Versioning](https://semver.org/spec/v2.0.0.html).
- Resolved an issue in the `applyNode` GraphQL API, where configuration values
set to an empty string were not saved to the `config` in the database.
- Fixed an issue where configuration conversion failures were silently ignored,
leading to incorrect None handling.
## [0.24.0] - 2024-11-19
Expand Down
65 changes: 44 additions & 21 deletions src/graphql/node/input.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{collections::HashMap, fmt};

use anyhow::Context as AnyhowContext;
use async_graphql::{types::ID, InputObject, Result};
use async_graphql::{types::ID, Error, InputObject, Result};

use super::{AgentKind, AgentStatus};

Expand Down Expand Up @@ -138,27 +138,50 @@ pub(super) fn create_draft_update(
.map(|agent| (agent.key.clone(), agent.config.clone()))
.collect();

let agents: Vec<review_database::Agent> = if let Some(new_agents) = new.agents {
new_agents
.into_iter()
.map(|agent_draft| {
let config = old_config_map
.get(&agent_draft.key)
.and_then(|config| config.as_ref().and_then(|c| c.clone().try_into().ok()));

review_database::Agent {
node: u32::MAX,
key: agent_draft.key,
kind: agent_draft.kind.into(),
status: agent_draft.status.into(),
config,
draft: agent_draft.draft.and_then(|draft| draft.try_into().ok()),
}
let agents: Vec<review_database::Agent> =
new.agents
.map(|new_agents| {
new_agents
.into_iter()
.map(|new_agent| {
let config =
match old_config_map.get(&new_agent.key) {
Some(config) => match config.as_ref() {
Some(c) => Some(c.clone().try_into().map_err(|_| {
Error::new("Failed to convert agent config")

Check warning on line 151 in src/graphql/node/input.rs

View check run for this annotation

Codecov / codecov/patch

src/graphql/node/input.rs#L151

Added line #L151 was not covered by tests
})?),
None => None,
},
None => {
return Err(Error::new(format!(
"Missing configuration for agent key: {}",
new_agent.key
)))

Check warning on line 159 in src/graphql/node/input.rs

View check run for this annotation

Codecov / codecov/patch

src/graphql/node/input.rs#L156-L159

Added lines #L156 - L159 were not covered by tests
}
};

let draft = match new_agent.draft {
Some(draft) => Some(
draft
.try_into()
.map_err(|_| Error::new("Failed to convert agent draft"))?,
),
None => None,
};

Ok(review_database::Agent {
node: u32::MAX,
key: new_agent.key,
kind: new_agent.kind.into(),
status: new_agent.status.into(),
config,
draft,
})
})
.collect::<Result<Vec<_>, _>>()
})
.collect()
} else {
Vec::new()
};
.transpose()?
.unwrap_or_default();

let giganto: Option<review_database::Giganto> = new.giganto.map(Into::into);

Expand Down

0 comments on commit d398d76

Please sign in to comment.