Handle metadata fetching errors gracefully#189
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughWhen the metadata service is unreachable, IDirectoryElementsService.completeElementAttribute catches ResourceAccessException, logs a warning, and returns elements with empty specificMetadata. ExploreTest simulates the failure and asserts the metadata endpoint returns a partial response with the expected element. ChangesGraceful metadata loading failure
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
# Conflicts: # src/test/java/org/gridsuite/explore/server/ExploreTest.java
|
| return lstElementAttribute.stream() | ||
| .map(elementAttributes -> populateMedataItem(elementAttributes, Map.of())) | ||
| .collect(Collectors.toList()); | ||
| } |
There was a problem hiding this comment.
| } | |
| List<Map<String, Object>> metadata = safeGetMetadata(lstElementAttribute); | |
| return metadata.stream().map(metadataItem -> { | |
| Object item = metadataItem.get("id"); | |
| if (item == null) { | |
| item = metadataItem.getOrDefault("uuid", ""); | |
| } | |
| ElementAttributes e = mapElementAttribute.get(item.toString()); | |
| return populateMedataItem(e, metadataItem); | |
| }).collect(Collectors.toList()); | |
| } | |
| private List<Map<String, Object>> safeGetMetadata(List<ElementAttributes> lstElementAttribute) { | |
| List<Map<String, Object>> metadata; | |
| try { | |
| metadata = getMetadata(lstElementAttribute.stream().map(ElementAttributes::getElementUuid).collect(Collectors.toList())); | |
| } catch (ResourceAccessException e) { | |
| String elementType = lstElementAttribute.isEmpty() ? "UNKNOWN" : lstElementAttribute.getFirst().getType(); | |
| LOGGER.warn("{} metadata service is unavailable, returning elements with empty specific metadata", elementType); | |
| metadata = Collections.nCopies(lstElementAttribute.size(), Map.of()); | |
| } | |
| return metadata; | |
| } |
Refactoring suggestion + maybe no need to log the error stack in the warn as we identify the type already, and that we enter this case only on ResourceAccessException



PR Summary
Handle metadata-service connectivity failures by catching ResourceAccessException in IDirectoryElementsService, logging the affected element type, and returning the elements with empty specificMetadata instead of failing the whole request.
This makes it possible to display elements in Gridexplore without having the metadata server up (like actions-server).