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

Fixes #18926: nodes API with include managementTechnologyDetails leads to error 500 response #3513

Conversation

fanf
Copy link
Member

@fanf fanf commented Feb 19, 2021

@fanf fanf force-pushed the bug_18926/nodes_api_with_include_managementtechnologydetails_leads_to_error_500_response branch from 1a80ec8 to 897040b Compare February 19, 2021 16:47
case (None, key) =>
InventoryMappingRudderError.MissingMandatory("Error when parsing agent security token: agent is undefined").fail
}
ZIO.foreach(agentWithKeys) { case (opt, key) => ((opt, key) match {
Copy link
Member

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?

Copy link
Member Author

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(....)
}

Copy link
Member

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

@Normation-Quality-Assistant
Copy link
Contributor

This PR is not mergeable to upper versions.
Since it is "Ready for merge" you must merge it by yourself using the following command:
rudder-dev merge https://github.com/Normation/rudder/pull/3513
-- Your faithful QA
Kant merge: "All our knowledge begins with the senses, proceeds then to the understanding, and ends with reason. There is nothing higher than reason."
(https://ci.normation.com/jenkins/job/merge-accepted-pr/35763/console)

@fanf
Copy link
Member Author

fanf commented Feb 28, 2021

OK, merging this PR

@fanf fanf merged commit a598d67 into Normation:branches/rudder/6.1 Feb 28, 2021
@fanf fanf deleted the bug_18926/nodes_api_with_include_managementtechnologydetails_leads_to_error_500_response branch March 15, 2024 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants