Skip to content
This repository was archived by the owner on Jun 3, 2021. It is now read-only.

Conversation

@soenkehahn
Copy link
Contributor

This change depends on a fork of yaml-rust,
https://github.com/hallettj/yaml-rust/tree/load_from_str_with_markers

@hallettj: Here's the PR with the cherry-picked commit.

Copy link
Contributor Author

@soenkehahn soenkehahn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this PR should add tests for the feature that it's implementing, even though the feature is tested through other tests. So something like steps_fail_with_yaml_source_locations. Maybe even two tests that demonstrate that the source locations actually point to different places in the yaml file when two different steps fail.

@@ -0,0 +1,32 @@
use yaml_rust;

#[derive(Clone, Copy, PartialEq, PartialOrd, Debug, Eq, Ord, Hash)]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need all these derived traits, or is this just your default list of things that you derive for everything?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, some of these I just copied over from the yaml-rust struct where they are necessary because markers form parts of hash keys. I'll push a change.

pub struct Marker {
pub line: usize,
pub col: usize,
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we implementing our own Marker and don't reuse the one from yaml-rust?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I construct Marker values in some tests. The fields in yaml_rust::Marker are private, and so is the constructor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, but shouldn't your changes to yaml-rust make those things public? If the first and only usage of the new yaml-rust version needs this to be public?

pub fn line(&self) -> usize {
let Marker { line, .. } = self;
*line
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need a getter function for this? Couldn't we just use the field?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point; I have removed the getter.

pub fn marker(&self) -> Option<Marker> {
let Step { marker, .. } = self;
*marker
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use the field marker?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have also removed this getter.

#[derive(PartialEq, Eq, Debug, Clone)]
pub struct Step {
pub command_matcher: CommandMatcher,
pub marker: Option<Marker>,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the cases where this can be None?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Markers come wrapped in Option from yaml-rust. We would have to use unwrap if we don't want the Option wrapper in Step.

In an early version of my changes to yaml-rust I did not have an option wrapper for markers. I remember having a good reason for adding the wrapper - something other than just the convenience of being able to implement From<Yaml> for Node. But I don't remember exactly what that reason was.

tests/run.rs Outdated
"error in {}.protocols.yaml: \
expected: array, got: Integer(42)",
expected: array, \
got: Node(Integer(42), Some(Marker {{ index: 10, line: 1, col: 10 }}))",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this test should be changed in this PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I changed this back. But I think it would be useful to include the source location in this error message in a future change.

@hallettj
Copy link
Contributor

hallettj commented Apr 2, 2019

I added tests specific to line number reporting, nice_error_with_yaml_source_line_number_when_string_step_fails and nice_error_with_yaml_source_line_number_when_hash_step_fails

@hallettj
Copy link
Contributor

hallettj commented Apr 2, 2019

@soenkehahn May I get a re-review?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants