Skip to content

Conversation

@yruslan
Copy link
Collaborator

@yruslan yruslan commented Jan 29, 2026

Summary by CodeRabbit

  • Refactor

    • Simplified resource-management utility: clearer control flow and direct return of action results, with improved exception propagation and suppressed-exception handling during resource close.
  • Tests

    • Expanded test coverage for resource scenarios, including null-resource cases and various exception propagation behaviors to validate the new flow.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 29, 2026

Walkthrough

Refactors 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

Cohort / File(s) Summary
Core Utility Implementation
pramen/core/src/main/scala/za/co/absa/pramen/core/utils/UsingUtils.scala
Rewrote using to return action result directly; removed Option-based result aggregation and separate thrown/suppressed tracking; unified exception handling so close exceptions are suppressed onto the action exception when both occur, otherwise thrown.
Test Suite Updates
pramen/core/src/test/scala/za/co/absa/pramen/core/tests/utils/UsingUtilsSuite.scala
Updated and added tests for null-resource behavior, including action throwing with a null resource and cases where the action returns null; renamed an existing test label for clarity.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰
I hopped through code with eager paws,
I chewed up Option-wrapped because,
Now exceptions nest but close is kind,
Nulls and returns I taught to mind,
A tidy burrow — neat and small.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changes: refactored UsingUtils to handle null resources and null return values, with corresponding test updates.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a 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 null resources (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".

@github-actions
Copy link

github-actions bot commented Jan 29, 2026

Unit Test Coverage

Overall Project 84.13% -0.01% 🍏
Files changed 78.13%

Module Coverage
pramen:core Jacoco Report 86.08% -0.01%
Files
Module File Coverage
pramen:core Jacoco Report UsingUtils.scala 87.93% -12.07%

@yruslan yruslan merged commit 7c82720 into main Jan 29, 2026
7 checks passed
@yruslan yruslan deleted the feature/using-support-nulls branch January 29, 2026 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants