Skip to content

Conversation

@skaerg
Copy link
Contributor

@skaerg skaerg commented Apr 9, 2025

@skaerg skaerg force-pushed the arch_26714/migrate_workflowservice_to_use_zio branch from ab4ea46 to 3cc9c9d Compare April 10, 2025 09:34
@skaerg
Copy link
Contributor Author

skaerg commented Apr 10, 2025

Commit modified

@skaerg skaerg force-pushed the arch_26714/migrate_workflowservice_to_use_zio branch from 3cc9c9d to 46b3ef0 Compare April 11, 2025 09:08
@skaerg
Copy link
Contributor Author

skaerg commented Apr 11, 2025

Commit modified

@skaerg skaerg force-pushed the arch_26714/migrate_workflowservice_to_use_zio branch from 46b3ef0 to 91a7590 Compare April 11, 2025 11:34
@skaerg
Copy link
Contributor Author

skaerg commented Apr 11, 2025

Commit modified

@skaerg skaerg force-pushed the arch_26714/migrate_workflowservice_to_use_zio branch from 91a7590 to 81f85b2 Compare April 11, 2025 17:11
@skaerg
Copy link
Contributor Author

skaerg commented Apr 11, 2025

Commit modified

Copy link
Contributor

@clarktsiory clarktsiory left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most changes look okay, there are some changes that need to be corrected before merging

Comment on lines 287 to 288
savedChangeRequest.toBox match {
case Full(id) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the error-handling here could be migrated using chainError, fold/either, etc.

Comment on lines 783 to 793
workflowLevelService.getForNodeGroup(CurrentUser.actor, change) match {
case eb: EmptyBox =>
val msg = s"Error when getting the validation workflow for changes in directive '${change.newGroup.name}'"
logger.warn(msg, eb)
JsRaw(s"alert('${msg}')")

case Full(workflowService) =>
workflowLevelService
.getForNodeGroup(CurrentUser.actor, change)
.chainError(s"Error when getting the validation workflow for changes in directive '${change.newGroup.name}'")
.either
.runNow match {
case Left(err) =>
logger.warn(err.fullMsg)
JsRaw(s"alert('${err.fullMsg}')")

case Right(workflowService) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The JsRaw alert should not output the full message (containing the details of the exception).
The previous msg should be kept instead

Comment on lines 240 to 248
workflowLevelService.getForGlobalParam(CurrentUser.actor, change) match {
case eb: EmptyBox =>
val msg = "An error occured when trying to find the validation workflow to use for that change."
logger.error(msg, eb)
JsRaw(s"alert('${msg}')") // JsRaw ok, const
workflowLevelService
.getForGlobalParam(CurrentUser.actor, change)
.chainError("An error occured when trying to find the validation workflow to use for that change.")
.either
.runNow match {
case Left(err) =>
logger.error(err.fullMsg)
JsRaw(s"alert('${err.fullMsg}')") // JsRaw ok, const
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous msg should be kept instead

Comment on lines 119 to 122
def save(changeRequest: ChangeRequest)(implicit cc: ChangeContext): IOResult[ChangeRequest] = {
implicit val qc: QueryContext = cc.toQuery

workflowEnabled().toBox.foreach {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As soon as the toBox is called, the save that is returning an IOResult is no longer lazy, so the method lacks transparency (we should follow the principle of "referential transparency" by enforcing that a method that returns an IOResult should always be lazy).

So, we should avoid the .toBox.foreach { ... }.toIO here and use the transformations on ZIO

Comment on lines 190 to 200
savedChangeRequest
.chainError("An error occurred while updating the parameter")
.fold(
err => {
logger.error(err.fullMsg)
formTracker.addFormError(error(err.fullMsg))
onFailure
},
res => res
)
.runNow
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A fold that does not apply any transformation on the "success" part should be a catchAll instead

@skaerg skaerg marked this pull request as ready for review April 16, 2025 14:06
@skaerg
Copy link
Contributor Author

skaerg commented Apr 18, 2025

PR updated with a new commit

@skaerg skaerg force-pushed the arch_26714/migrate_workflowservice_to_use_zio branch from 6fea465 to bd14500 Compare April 18, 2025 14:10
@skaerg
Copy link
Contributor Author

skaerg commented Apr 18, 2025

Commit modified

@skaerg
Copy link
Contributor Author

skaerg commented Apr 18, 2025

PR rebased

@skaerg skaerg force-pushed the arch_26714/migrate_workflowservice_to_use_zio branch from bd14500 to 9ad63dc Compare April 18, 2025 14:13
@skaerg skaerg force-pushed the arch_26714/migrate_workflowservice_to_use_zio branch from 9ad63dc to 26e197f Compare April 18, 2025 14:15
@skaerg
Copy link
Contributor Author

skaerg commented Apr 18, 2025

Commit modified

Copy link
Contributor

@clarktsiory clarktsiory left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM ! Tested and the snippets are still rendering correctly, all issues regarding having liftweb code within ZIO effects seem to have been fixed.

@Normation-Quality-Assistant
Copy link
Contributor

OK, merging this PR

@Normation-Quality-Assistant Normation-Quality-Assistant merged commit 42e3e6e into Normation:branches/rudder/9.0 Apr 22, 2025
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants