From 3df481e35ea6ee39b03b456fe4b2b18639e35cd4 Mon Sep 17 00:00:00 2001 From: adityamparikh Date: Fri, 24 Apr 2026 14:14:31 -0400 Subject: [PATCH 1/2] fix: narrow catch clauses in fetchCacheMetrics/fetchHandlerMetrics Change catch from RuntimeException to SolrException in fetchCacheMetrics() and fetchHandlerMetrics(). This still catches Solr 10's RemoteSolrException (subclass of SolrException) for graceful degradation when /admin/mbeans is unavailable, but no longer swallows programming bugs like NPE or ClassCastException. Closes #4 Signed-off-by: Aditya Parikh Co-Authored-By: Claude Opus 4.6 (1M context) Signed-off-by: adityamparikh --- .../apache/solr/mcp/server/collection/CollectionService.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/apache/solr/mcp/server/collection/CollectionService.java b/src/main/java/org/apache/solr/mcp/server/collection/CollectionService.java index 011d278e..2860c9fa 100644 --- a/src/main/java/org/apache/solr/mcp/server/collection/CollectionService.java +++ b/src/main/java/org/apache/solr/mcp/server/collection/CollectionService.java @@ -40,6 +40,7 @@ import org.apache.solr.client.solrj.response.LukeResponse; import org.apache.solr.client.solrj.response.QueryResponse; import org.apache.solr.client.solrj.response.SolrPingResponse; +import org.apache.solr.common.SolrException; import org.apache.solr.common.params.ModifiableSolrParams; import org.apache.solr.common.util.NamedList; import org.apache.solr.mcp.server.config.SolrConfigurationProperties; @@ -692,7 +693,7 @@ public QueryStats buildQueryStats(QueryResponse response) { CacheStats stats = extractCacheStats(coreMetrics); return isCacheStatsEmpty(stats) ? null : stats; - } catch (SolrServerException | IOException | RuntimeException _) { + } catch (SolrServerException | IOException | SolrException _) { return null; } } @@ -810,7 +811,7 @@ private CacheStats extractCacheStats(NamedList coreMetrics) { HandlerStats stats = new HandlerStats(selectHandler, updateHandler); return isHandlerStatsEmpty(stats) ? null : stats; - } catch (SolrServerException | IOException | RuntimeException _) { + } catch (SolrServerException | IOException | SolrException _) { return null; } } From ab1aa24d3c0196f00ba05e55372c95be99a523bc Mon Sep 17 00:00:00 2001 From: Aditya Parikh Date: Thu, 20 Aug 2026 11:06:03 -0400 Subject: [PATCH 2/2] docs: correct the Solr 10 metrics catch described in AGENTS.md The Solr 10 Compatibility section said getCacheMetrics()/getHandlerMetrics() "catch RuntimeException (which covers RemoteSolrException)". This PR is what makes that untrue, so the correction belongs here rather than trailing behind in a follow-up. Also records why the narrower catch is the right one: RemoteSolrException extends SolrException, so Solr 10's missing /admin/mbeans still degrades to null, while an unrelated runtime failure in metrics parsing now surfaces as a bug instead of masquerading as "metrics unavailable". Note CLAUDE.md is a symlink to AGENTS.md, so this is the single source. Signed-off-by: Aditya Parikh --- AGENTS.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 7d7ce524..325ab1c7 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -339,9 +339,11 @@ The Solr Docker image used in tests is configurable via the `solr.test.image` sy ### Solr 10 Compatibility Solr 10.0.0 is fully supported with the JSON wire format. The `/admin/mbeans` endpoint was -removed in Solr 10; `getCacheMetrics()` and `getHandlerMetrics()` now catch `RuntimeException` -(which covers `RemoteSolrException`) so they degrade gracefully and return `null`. Tests that -check `cacheStats` and `handlerStats` already handle `null` values. +removed in Solr 10; `getCacheMetrics()` and `getHandlerMetrics()` catch `SolrException` (which +`RemoteSolrException` extends) so they degrade gracefully and return `null`. Tests that check +`cacheStats` and `handlerStats` already handle `null` values. The catch is deliberately *not* +`RuntimeException`: an unrelated runtime failure inside metrics parsing should surface as a bug, +not be silently reported as "metrics unavailable". Remaining known differences from Solr 9: - **`/admin/mbeans` removed:** Cache and handler stats from `getCollectionStats()` will always be `null` on Solr 10. A future migration to `/admin/metrics` will restore these metrics.