8000 `find` should return `null` when the pattern wasn't found · Issue #1383 · vectordotdev/vrl · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
B01C

find should return null when the pattern wasn't found #1383

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

Open
simplepad opened this issue Apr 15, 2025 · 0 comments
Open

find should return null when the pattern wasn't found #1383

simplepad opened this issue Apr 15, 2025 · 0 comments
Labels
type: bug A code related bug vrl: stdlib Changes to the standard library

Comments

@simplepad
Copy link
Contributor

A note for the community

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.

Problem

Discussed in #1311

Right now it returns -1, which from what I can see is somewhat of a special case, because in other functions if something could not be found, null is returned. Returning -1 might introduce hidden bugs if the return value is not analyzed, for example:

input = "foobar"
index = find!(input, "123")
output = slice!(input, index)
assert_eq!(output, "r")

This code will compile without issues, and the value stored in output will be "r". Maybe it would be better to return null (which will fail the slice!() function) or make the find!() function fail if the pattern wasn't found, requiring the developer to handle that case explicitly.

VRL Program

input = "foobar"
index = find!(input, "123")
output = slice!(input, index)
assert_eq!(output, "r")

VRL and/or Vector Version

VRL Version: 0.22.0

Debug Output


Example

Playground Link

Additional Context

No response

References

Discussed in #1311

@simplepad simplepad added the type: bug A code related bug label Apr 15, 2025
@pront pront added the vrl: stdlib Changes to the standard library label Apr 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A code related bug vrl: stdlib Changes to the standard library
Projects
None yet
Development

No branches or pull requests

2 participants
0