Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle configuration conversion failures explicitly #373

Merged
merged 1 commit into from
Jan 13, 2025
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,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 @@
.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
Loading