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

Fix std::fmt::Display for abort expressions #830

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

DylanRJohnston
Copy link

Fixes #829. I couldn't see any tests for this code, but a very simply one exists as I wrote in the issue. Let me know if you want that included and where it should live.

    #[test]
    fn abort_display_isomorphism() {
        let expression = r#"abort "error message""#;

        assert_eq!(
            format!("{expression}\n"),
            vrl::parser::parse(expression).unwrap().to_string()
        )
    }

@DylanRJohnston
Copy link
Author

Just noticed a few more instances of failing to serialize out re-parsable expressions, namely infailable function calls and queries.

@@ -933,7 +933,7 @@ pub struct Query {

impl fmt::Display for Query {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}{}", self.target, self.path)
write!(f, "{}.{}", self.target, self.path)
Copy link
Author

Choose a reason for hiding this comment

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

Without this variable queries end up mushed together e.g. foo.bar becomes foobar however that then causes .foo.bar to become ..foo.bar without the change to QueryTarget below.

@@ -958,7 +958,7 @@ impl fmt::Display for QueryTarget {
match self {
Internal(v) => v.fmt(f),
External(prefix) => match prefix {
PathPrefix::Event => write!(f, "."),
PathPrefix::Event => write!(f, ""),
Copy link
Author

Choose a reason for hiding this comment

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

Should probably just remove this write! all together? If I understand correctly, and based on my testing QueryTarget always appears with a . after it even if OwnedValuePath is empty. So this is safe.

@pront pront requested review from pront and jszwedko May 7, 2024 13:16
@pront
Copy link
Collaborator

pront commented May 7, 2024

Hi @DylanRJohnston, your project sounds quite interesting but this PR breaks a test. I don't have time to do a thorough review but for faster dev iterations you can locally use ./scripts/checks.sh or just ./scripts/checks.sh vrl_tests tests.

@pront pront marked this pull request as draft May 17, 2024 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Abort expression formats incorrectly
2 participants