Skip to content

Commit 3cb2918

Browse files
authored
DAG-2777 Added better logging around errors in yaml parsing
1 parent 7a9e467 commit 3cb2918

File tree

8 files changed

+70
-15
lines changed

8 files changed

+70
-15
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## 0.7.9 - 2022-07-31
4+
* DAG-2777: Added better logging around yaml failures
5+
36
## 0.7.8 - 2022-05-25
47
* Update burn in tags API to accommodate all required and suggested buildvariants.
58

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "mongo-task-generator"
33
description = "Dynamically split evergreen tasks into subtasks for testing the mongodb/mongo project."
44
license = "Apache-2.0"
5-
version = "0.7.8"
5+
version = "0.7.9"
66
repository = "https://github.com/mongodb/mongo-task-generator"
77
authors = ["Decision Automation Group <[email protected]>"]
88
edition = "2018"
@@ -28,7 +28,7 @@ shellexpand = "2.1"
2828
shrub-rs = "0.5.1"
2929
tokio = { version = "1", features = ["full"] }
3030
tracing = "0.1"
31-
tracing-subscriber = {version = "0.3", features = ["json", "fmt", "std"]}
31+
tracing-subscriber = { version = "0.3", features = ["json", "fmt", "std"] }
3232

3333
[dev-dependencies]
3434
assert_cmd = "2.0"

src/generate_sub_tasks_config.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::{collections::HashSet, path::Path};
2+
use tracing::error;
23

34
use anyhow::Result;
45
use serde::Deserialize;
@@ -10,9 +11,18 @@ pub struct GenerateSubTasksConfig {
1011

1112
impl GenerateSubTasksConfig {
1213
pub fn from_yaml_file<P: AsRef<Path>>(location: P) -> Result<Self> {
13-
let contents = std::fs::read_to_string(location)?;
14+
let contents = std::fs::read_to_string(&location)?;
1415

15-
Ok(serde_yaml::from_str(&contents)?)
16+
let subtasks: Result<Self, serde_yaml::Error> = serde_yaml::from_str(&contents);
17+
if subtasks.is_err() {
18+
error!(
19+
file = location.as_ref().display().to_string(),
20+
contents = &contents,
21+
"Failed to parse yaml for GenerateSubTasksConfig from file",
22+
);
23+
}
24+
25+
Ok(subtasks?)
1626
}
1727

1828
pub fn ignore_missing_large_distro(&self, build_variant_name: &str) -> bool {

src/main.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use mongo_task_generator::{
1010
generate_configuration, Dependencies, ExecutionConfiguration, ProjectInfo,
1111
};
1212
use serde::Deserialize;
13-
use tracing::{event, Level};
13+
use tracing::{error, event, Level};
1414
use tracing_subscriber::fmt::format;
1515

1616
const DEFAULT_EVG_AUTH_FILE: &str = "~/.evergreen.yml";
@@ -41,7 +41,17 @@ impl EvgExpansions {
4141
/// * `path` - Path to YAML file to read.
4242
pub fn from_yaml_file(path: &Path) -> Result<Self> {
4343
let contents = std::fs::read_to_string(path)?;
44-
Ok(serde_yaml::from_str(&contents)?)
44+
45+
let evg_expansions: Result<Self, serde_yaml::Error> = serde_yaml::from_str(&contents);
46+
if evg_expansions.is_err() {
47+
error!(
48+
file = path.display().to_string(),
49+
contents = &contents,
50+
"Failed to parse yaml for EvgExpansions from file",
51+
);
52+
}
53+
54+
Ok(evg_expansions?)
4555
}
4656

4757
/// File to store generated configuration under.

src/resmoke/burn_in_proxy.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::{path::Path, time::Instant};
22

33
use anyhow::Result;
44
use serde::Deserialize;
5-
use tracing::{event, Level};
5+
use tracing::{error, event, Level};
66

77
use crate::resmoke::external_cmd::run_command;
88

@@ -100,7 +100,16 @@ impl BurnInDiscovery for BurnInProxy {
100100
"Burn In Discovery Finished"
101101
);
102102

103-
let output: DiscoveredTaskList = serde_yaml::from_str(&cmd_output)?;
104-
Ok(output.discovered_tasks)
103+
let output: Result<DiscoveredTaskList, serde_yaml::Error> =
104+
serde_yaml::from_str(&cmd_output);
105+
if output.is_err() {
106+
error!(
107+
command = cmd.join(" "),
108+
command_output = &cmd_output,
109+
"Failed to parse yaml from discover tasks command output",
110+
);
111+
}
112+
113+
Ok(output?.discovered_tasks)
105114
}
106115
}

src/resmoke/resmoke_proxy.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::{path::Path, str::FromStr, time::Instant};
22

33
use anyhow::Result;
44
use serde::Deserialize;
5-
use tracing::{event, Level};
5+
use tracing::{error, event, Level};
66

77
use super::{external_cmd::run_command, resmoke_suite::ResmokeSuiteConfig};
88

@@ -95,8 +95,17 @@ impl TestDiscovery for ResmokeProxy {
9595
"Resmoke test discovery finished"
9696
);
9797

98-
let output: TestDiscoveryOutput = serde_yaml::from_str(&cmd_output)?;
99-
Ok(output
98+
let output: Result<TestDiscoveryOutput, serde_yaml::Error> =
99+
serde_yaml::from_str(&cmd_output);
100+
if output.is_err() {
101+
error!(
102+
command = cmd.join(" "),
103+
command_output = &cmd_output,
104+
"Failed to parse yaml from discover tests command output",
105+
);
106+
}
107+
108+
Ok(output?
100109
.tests
101110
.into_iter()
102111
.filter(|f| Path::new(f).exists())
@@ -150,7 +159,16 @@ impl MultiversionConfig {
150159
cmd.append(&mut script.iter().map(|s| s.as_str()).collect());
151160
cmd.append(&mut vec!["multiversion-config"]);
152161
let cmd_output = run_command(&cmd).unwrap();
153-
Ok(serde_yaml::from_str(&cmd_output)?)
162+
let multiversion_config: Result<MultiversionConfig, serde_yaml::Error> =
163+
serde_yaml::from_str(&cmd_output);
164+
if multiversion_config.is_err() {
165+
error!(
166+
command = cmd.join(" "),
167+
command_output = &cmd_output,
168+
"Failed to parse yaml from multiversion config command output",
169+
);
170+
}
171+
Ok(multiversion_config?)
154172
}
155173

156174
/// Get the required FCV tag for the lts version.

src/resmoke/resmoke_suite.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::{collections::HashSet, str::FromStr};
55
use anyhow::Result;
66
use serde::{Deserialize, Serialize};
77
use serde_yaml::{Error, Value};
8+
use tracing::error;
89

910
#[derive(Serialize, Debug, Clone, Deserialize)]
1011
#[serde(untagged)]
@@ -79,7 +80,11 @@ impl FromStr for ResmokeSuiteConfig {
7980

8081
/// Read Resmoke suite configuration from the given string.
8182
fn from_str(s: &str) -> Result<Self, Self::Err> {
82-
serde_yaml::from_str(s)
83+
let resmoke_suite_config: Result<Self, serde_yaml::Error> = serde_yaml::from_str(s);
84+
if resmoke_suite_config.is_err() {
85+
error!(yaml = s, "Failed to parse yaml for ResmokeSuiteConfig",);
86+
}
87+
resmoke_suite_config
8388
}
8489
}
8590

0 commit comments

Comments
 (0)