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

W-11222217: generate error message when attempting to migrate mel emp… #685

Merged
merged 5 commits into from
Aug 5, 2022

Conversation

andres-rad
Copy link
Contributor

…ty literal


it should "fail with empty literal" in {
Migrator.migrate("payload == empty").metadata.children.head shouldBe NonMigratable("expressions.emptyLiteral")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we migrate to isEmpty(payload)

Copy link
Contributor Author

@andres-rad andres-rad Aug 3, 2022

Choose a reason for hiding this comment

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

I looked into it, but the empty comparison differs from isEmpty in a couple of cases:

  • 0 == empty and isEmpty(0)
  • false == empty and isEmpty(false)

Maybe the error message should be a bit more specific?

Copy link
Contributor

Choose a reason for hiding this comment

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

I see now we could migrate it to payload == 0 or payload == false or isEmpty(payload)

Copy link
Contributor

Choose a reason for hiding this comment

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

Or migrate it to just isEmpty(payload) with a warning saying that some use cases may not work. But I prefer to migrate it to something that just throw an error. I could imagine not many people using those weird semantics of the == empty

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see now we could migrate it to payload == 0 or payload == false or isEmpty(payload)

I can add this, but there is one other case that I forgot to add, empty also returns true when compared against a string with only whitespaces. That is a case that we can't recognize because we would need to know if the argument is a String to trim it in the comparison.

I also don't imagine that a lot of people use this feature, but it feels wrong to migrate it with only a warning if we are potentially breaking the application. If you think it's not a problem I can migrate it to this case and add in the message that it breaks if the argument was a string with only whitespaces.

Copy link
Contributor

Choose a reason for hiding this comment

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

So it would be payload == 0 or payload == false or isEmpty(payload) or (payload is String and isBlank(payload)) The problem for me is that we have two options one is that we try to migrate with the most elegant but less compatible or we can try to migrate with the more compatible but less readable (elegant) that is this big expression. I'm ok with both things either migrate to isEmpty(payload) with a warning saying this may not work in all cases or migrate to ugly expression. @svacas what do you prefer?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would go with the nice expression + warning, that should cover most of the cases and go along with the MMA philosophy of doing a best effort without getting too convoluted

Copy link
Contributor Author

@andres-rad andres-rad Aug 3, 2022

Choose a reason for hiding this comment

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

Nice expression being just isEmpty(payload) right?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes

machaval
machaval previously approved these changes Aug 3, 2022
@@ -195,4 +195,8 @@ class MigratorTest extends FlatSpec with Matchers {
it should "migrate mel expression with isCausedBy function" in {
Migrator.migrate("exception.causedBy(org.mule.RuntimeException)").getGeneratedCode() shouldBe "%dw 2.0\n---\nJava::isCausedBy(error.cause, 'org.mule.RuntimeException', false)"
}

it should "fail with empty literal" in {
Copy link
Contributor

Choose a reason for hiding this comment

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

description should be something like migrate mel expression with empty and raise warning
if possible verify the migrated expression and also using != besides ==

@svacas svacas self-requested a review August 4, 2022 12:26
Copy link
Contributor

@svacas svacas left a comment

Choose a reason for hiding this comment

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

see comment regarding the test

@andres-rad andres-rad merged commit ac7e387 into master Aug 5, 2022
@andres-rad andres-rad deleted the W-11222217/handle-mel-empty-literal branch August 5, 2022 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants