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

Change LogEvent::insert function to return a Result<Option<Value>> #21213

Open
pront opened this issue Sep 5, 2024 · 0 comments
Open

Change LogEvent::insert function to return a Result<Option<Value>> #21213

pront opened this issue Sep 5, 2024 · 0 comments
Labels
type: tech debt A code change that does not add user value.

Comments

@pront
Copy link
Contributor

pront commented Sep 5, 2024

This is an idea for improving the insertion API. I noticed that insert silently fails when inserting inserting special paths like a-b. See the following test for example:

#[test]
fn special_path_insert() {
    let mut log = LogEvent::default();
    log.insert("a-b", 0); // The path segment is invalid, it needs to be quoted.
    log.insert("\"a-c\"", 1); // Valid path segment.

    assert_eq!(log.get("a-b"), None); } // This returns nothing.
    assert_eq!(log.get("\"a-c\""), Some(&1.into())); // OK

Changing the return type to vector_common::Result<Option<Value>> would require the user to handle a failed insertion. This can prevent subtle bugs. However, this would require a lot of refactoring.

Edit: This is actually only relevant when the string_path VRL crate feature is enabled. This feature is off by default.

@pront pront changed the title Change LogEvent::insert function to return a vector_common::Result<Option<Value>> Change LogEvent::insert function to return a Result<Option<Value>> Sep 5, 2024
@jszwedko jszwedko added the type: tech debt A code change that does not add user value. label Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: tech debt A code change that does not add user value.
Projects
None yet
Development

No branches or pull requests

2 participants