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
Fixes #18926: nodes API with include managementTechnologyDetails leads to error 500 response #3513
Conversation
…s to error 500 response
1a80ec8
to
897040b
Compare
case (None, key) => | ||
InventoryMappingRudderError.MissingMandatory("Error when parsing agent security token: agent is undefined").fail | ||
} | ||
ZIO.foreach(agentWithKeys) { case (opt, key) => ((opt, key) match { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do you need the extra case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we use a syntax shortcut in methods accepting function as argument: you can create a partial function with the following syntax { case x => ... }
and so use it directly as argument, what we regularly do for map
and alike function - and in that case, we are careful to use a partial function which is actually total by not imposing restriction on the x
:
myUserList.map { case User(name, age) => name.capitalize }
But that really syntax for partial function, so you can put as many guard as you want in the pattern, use as many pattern as you want, and even don't make it total (and be sad when the pattern match exception happens):
myUserList.map {
case User(name, age) if age > 17 =>
case User(name, age) if age > 5 =>
// and pattern match exception when age <= 6, but YOLO!
}
So in our case, since I wanted to have a different logic for the two cases of Option
:
ZIO.foreach(agentWithKeys) {
case (Some(agent), key) => ...
case (None, key) =>
}
But then, I needed to apply a fold
on result, and I don't know of a syntax that allow to do that with several pattern match in the partial function syntact, so I reverted to the usual pattern match syntax and only one branch for the partial function:
ZIO.foreach(agentWithKeys) { case (opt, key) => //that's for the function arg of `foreach`
(opt, key) match { // that's a standard pattern matching
case (Some(agent), key) => ...
case (None, key) =>
}
}
And with the fold:
ZIO.foreach(agentWithKeys) { case (opt, key) => //that's for the function arg of `foreach`
((opt, key) match { // that's a standard pattern matching
case (Some(agent), key) => ...
case (None, key) =>
}).fold(....)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the time spent for the superb explanation of why adding the extra case, i learnt something
This PR is not mergeable to upper versions. |
OK, merging this PR |
https://issues.rudder.io/issues/18926