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 9 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
Contributor

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
@pront
Copy link
Contributor

pront commented Jun 20, 2024

Hi @DylanRJohnston, since this is deep change, it is also worth pointing Vector's VRL dependency to this sha and see if those CI checks are passing.

@DylanRJohnston
Copy link
Author

DylanRJohnston commented Jun 21, 2024

Hey @pront apologies I was waiting until the project was complete before coming back to fixing this pull request as I keep uncovering new problems as the project progresses and I didn't want to waste everyone's time with lots of pull requests. Since these changes are only needed at transpile time I've been able to get away with just using a fork for now although I am very interested in getting something like these changes merged into upstream.

I also made a fairly controversial decision to overload the fmt::Formatter width property to carry the indentation level for pretty printing of nested scopes and I wasn't sure you guys would approve of abusing it like that although I can't see any other way other than writing a whole separate serialization strategy that could carry information like that instead of the current reliance on recursive invocation of fmt::Display.

I also want to write some more comprehensive tests that ensure the parse <-> serialize isomorphism beyond just the edge cases I've discovered assuming this is a property that the VRL project wants to maintain?

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