-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Should remap emit a warning if we del
a field that doesn't exist?
#5566
Comments
Throwing an error by default seems overly aggressive here (just a gut feeling), but perhaps that could be enabled via an optional arg:
|
I like @lucperkins suggestion, or even a |
Or, we could have |
You could error yourself in that case: assert(del(.foo), "failed to delete .foo") Or log: if !del(.foo) {
log("failed to delete .foo", level = "warn")
} Or whatever else you want to do. |
For what it's worth, the old transform logged it as a |
Good point. I would still be favouring TRL not logging anything by default (the |
Just noting that this won't allow differentiation between undefined and defined, but with a value of |
I’m not sure I understand what you mean @jszwedko. I think the confusion might come from the fact that you think the However, your comment reminds me that we did decide to update this function to take only a single path and return the value of the path that was deleted, and I still think that is a desireable property to have. So I retract my proposal, because in that case, indeed, we can’t have it return a boolean value. I also realize now that the So given this, I’m almost inclined to say: when deleting a path, you have to handle the error case for when a path does not exist. For example: .timestamp = to_timestamp(del(.ts), default = now())
// or
if ok($json = parse_json(del(.message))) {
. = $json
} else {
.error = “unable to parse message field”
}
// or
.bytes = if ok($bytes = to_int(del(.bytes))) {
$bytes
} else {
0
}
// or with other error handling functions, which is orthogonal to this discussion
.bytes = ok_or(to_int(del(.bytes)), 0) Our error handling story is still being fleshed out, so I expect any minor inconvenience this causes right now to no longer be an issue in the future. |
Aha, yes, I was thinking about it returning the deleted value, but forgot that didn't happen yet. |
Closing in favor of #5779 |
If in Remap you run
del
on a field that doesn't exist it silently does nothing.Would it be worth emitting a warning if this occurs?
The chances are that the user has made an error if this happens and things may not be working as expected, but they won't be able to identify the problem. Emitting a warning would help with the debugging.
There are people who may want to
del
even if the field doesn't exist and will not want the warning. For those users, they could wrap the call in anexists
to supress the unneccessary warning.The text was updated successfully, but these errors were encountered: