-
Notifications
You must be signed in to change notification settings - Fork 3
Allow 'using' implementation support null resources and null return values #705
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
Conversation
WalkthroughRefactors the using utility to return the action result directly and consolidates exception handling into a single action exception flow that suppresses close exceptions when appropriate. Adds tests covering null-resource scenarios and action/null-return interactions. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
pramen/core/src/main/scala/za/co/absa/pramen/core/utils/UsingUtils.scala (1)
23-26: ScalaDoc contradicts new null‑resource behavior.The comment says “Null resources are not supported,” but the implementation now allows
nullresources (Line 43) and skips close. Please update the ScalaDoc to match the intended behavior.
🤖 Fix all issues with AI agents
In `@pramen/core/src/main/scala/za/co/absa/pramen/core/utils/UsingUtils.scala`:
- Around line 34-61: The try/finally currently only captures NonFatal from
action, allowing fatal Throwables to be masked by a later close() NonFatal;
change the logic in the method (variables: openedResource, action,
actionExceptionOpt) to catch Throwable from the action block, store it in
actionExceptionOpt and immediately rethrow it after attempting to close the
resource (i.e., in finally: if openedResource != null, try close(); on close
failure, if actionExceptionOpt is defined addSuppressed(closeException) and
rethrow the original action exception; if no action exception then throw the
close exception). Also update the ScalaDoc comment that currently says "Null
resources are not supported" to reflect that null resources are handled.
In
`@pramen/core/src/test/scala/za/co/absa/pramen/core/tests/utils/UsingUtilsSuite.scala`:
- Line 67: The test label in UsingUtilsSuite.scala currently reads "handle a
null resource resource and action throw" (the test name string in the spec) and
contains a duplicated "resource"; update that test description string to remove
the duplicate so it reads e.g. "handle a null resource and action throw" (or
another concise, grammatically correct label) without changing the test
implementation in the surrounding "handle a null resource resource and action
throw" spec block.
- Line 57: Update the test label string to remove the duplicated word so the
spec reads "handle a null resource" instead of "handle a null resource resource"
— locate the test definition that currently uses the string literal "handle a
null resource resource" (in UsingUtilsSuite) and change it to "handle a null
resource".
pramen/core/src/main/scala/za/co/absa/pramen/core/utils/UsingUtils.scala
Outdated
Show resolved
Hide resolved
pramen/core/src/test/scala/za/co/absa/pramen/core/tests/utils/UsingUtilsSuite.scala
Outdated
Show resolved
Hide resolved
pramen/core/src/test/scala/za/co/absa/pramen/core/tests/utils/UsingUtilsSuite.scala
Outdated
Show resolved
Hide resolved
Unit Test Coverage
Files
|
Summary by CodeRabbit
Refactor
Tests
✏️ Tip: You can customize this high-level summary in your review settings.