-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fix/expunge historical version exception message #6880
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
base: master
Are you sure you want to change the base?
Fix/expunge historical version exception message #6880
Conversation
…on message for missing entries
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.
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
Comments suppressed due to low confidence (1)
hapi-fhir-storage/src/main/java/ca/uhn/fhir/jpa/dao/expunge/PartitionRunner.java:130
- [nitpick] Consider adding a separator (e.g., ': ') between Msg.code(1085) and cause.getMessage() to improve the clarity of the exception message.
throw new InternalErrorException(Msg.code(1085) + cause.getMessage(), cause);
Formatting check succeeded! |
…cal-version-exception-message
Formatting check succeeded! |
myResourceHistoryTableDao.findById(theNextVersionId).orElseThrow(IllegalArgumentException::new); | ||
ResourceHistoryTable version = myResourceHistoryTableDao | ||
.findById(theNextVersionId) | ||
.orElseThrow(() -> new IllegalArgumentException(MessageFormat.format( |
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.
I guess we should probably include an error code here - We try to include them on all newly thrown exception messages that might end up visible to an end user. (FYI we use this page to reserve them)
.orElseThrow(() -> new IllegalArgumentException(MessageFormat.format( | |
.orElseThrow(() -> new IllegalArgumentException(Msg.code(2701) + MessageFormat.format( |
ResourceHistoryTablePk pk = new ResourceHistoryTablePk(); | ||
pk.setPartitionIdValue(42); | ||
// set versionId via reflection to avoid null in message | ||
Field versionIdField = ResourceHistoryTablePk.class.getDeclaredField("myVersionId"); |
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.
IMO we could just add a setter to this field so the test has better type safety... No harm in adding it, it's just not there 'cause it wasn't needed before
when(myResourceHistoryTableDao.findById(pk)).thenReturn(Optional.empty()); | ||
|
||
AtomicInteger remaining = new AtomicInteger(1); | ||
IllegalArgumentException ex = assertThrows( |
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.
Nitpick: This is fine, but @fil512 just pointed out to me how much nicer the assertThatThrownBy syntax can be for this kind of assertion the other day:
hapi-fhir/hapi-fhir-base/src/test/java/ca/uhn/fhir/interceptor/executor/InterceptorServiceTest.java
Lines 698 to 700 in 75162c5
assertThatThrownBy(() -> myInterceptorService.runWithFilterHooks(Pointcut.TEST_FILTER, myParams, mySupplier)) | |
.hasMessageContaining("Supplier was not executed in filter") | |
.hasMessageContaining("InterceptorServiceTest$FilterHooks$1.testFilter"); |
Summary
Improve exception handling in the asynchronous Expunge job so that missing historical versions throw a clear, contextual error instead of HAPI‑2223: null.
Changes
In JpaResourceExpungeService.expungeHistoricalVersion(), replace orElseThrow(IllegalArgumentException::new) with a lambda that includes the missing version’s ID and partition in the exception message.
Update PartitionRunner’s error‑handling to extract cause.getMessage() and propagate it, ensuring the logged and thrown InternalErrorException carries the real root‑cause text.
Add a simple unit test to verify that an absent history entry yields a non‑null, descriptive exception message.
Related issue
Closes #6879