From 21a1ec46c7f432883e4451eea4bdb994aeba0de9 Mon Sep 17 00:00:00 2001 From: iklas Date: Wed, 2 Dec 2026 03:52:34 -0800 Subject: [PATCH] fix(#15034): COMPACT INDEX of an index that does not exist answers 400, not 500 The index is resolved before the try that wraps every failure in an IndexException, as REBUILD INDEX does, so a missing name is refused with the lookup's SchemaException (HTTP 400, gRPC NOT_FOUND) instead of an IndexException that reads as a server fault. Co-Authored-By: Claude Opus 5.5 --- .../query/sql/parser/CompactIndexStatement.java | 6 +++++- .../arcadedb/index/CompactIndexStatementTest.java | 13 +++++++++++++ .../http/handler/HttpErrorStatusServerTest.java | 6 ++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/engine/src/main/java/com/arcadedb/query/sql/parser/CompactIndexStatement.java b/engine/src/main/java/com/arcadedb/query/sql/parser/CompactIndexStatement.java index de3916959a6..5977c308646 100644 --- a/engine/src/main/java/com/arcadedb/query/sql/parser/CompactIndexStatement.java +++ b/engine/src/main/java/com/arcadedb/query/sql/parser/CompactIndexStatement.java @@ -63,6 +63,10 @@ public ResultSet executeDDL(final CommandContext context) { final DatabaseInternal database = context.getDatabase(); database.checkPermissionsOnDatabase(SecurityDatabaseUser.DATABASE_ACCESS.UPDATE_SCHEMA); + // Resolved outside the try below, as REBUILD INDEX does (issue #15034): a name the schema does not have is the caller's + // mistake, refused with the SchemaException the lookup raises, not wrapped in an IndexException that reads as a server fault + final Index namedIndex = all ? null : database.getSchema().getIndexByName(name.getValue()); + final ResultInternal result = new ResultInternal(database); result.setProperty("operation", "compact index"); @@ -81,7 +85,7 @@ public ResultSet executeDDL(final CommandContext context) { if (idx.isAutomatic() && !(idx instanceof TypeIndex)) targetIndexes.add(idx); } else - targetIndexes.add(database.getSchema().getIndexByName(name.getValue())); + targetIndexes.add(namedIndex); int stepIndex = 0; for (final Index idx : targetIndexes) { diff --git a/engine/src/test/java/com/arcadedb/index/CompactIndexStatementTest.java b/engine/src/test/java/com/arcadedb/index/CompactIndexStatementTest.java index cf36777da35..0bd2b9397d4 100644 --- a/engine/src/test/java/com/arcadedb/index/CompactIndexStatementTest.java +++ b/engine/src/test/java/com/arcadedb/index/CompactIndexStatementTest.java @@ -21,6 +21,7 @@ import com.arcadedb.GlobalConfiguration; import com.arcadedb.TestHelper; import com.arcadedb.database.MutableDocument; +import com.arcadedb.exception.SchemaException; import com.arcadedb.index.sparsevector.LSMSparseVectorIndex; import com.arcadedb.query.sql.executor.Result; import com.arcadedb.query.sql.executor.ResultSet; @@ -34,6 +35,7 @@ import java.util.Random; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; /** * Regression test for issue #5144: index compaction must be reachable from SQL (and therefore HTTP) @@ -152,6 +154,17 @@ void compactLsmTreeIndexActuallyMergesViaSql() { } } + /** + * Issue #15034: a name the schema does not have is the caller's mistake, refused with the lookup's SchemaException as + * REBUILD INDEX and DROP INDEX refuse it, not wrapped in an IndexException (HTTP 500). + */ + @Test + void compactingAnIndexThatDoesNotExistIsRefusedAsASchemaError() { + assertThatThrownBy(() -> database.command("sql", "COMPACT INDEX Issue15034Nope")) + .isInstanceOf(SchemaException.class) + .hasMessageContaining("Issue15034Nope"); + } + private void insertDocs(final int n, final int seedOffset) { database.transaction(() -> { final Random rnd = new Random(0xCAFEL + seedOffset); diff --git a/server/src/test/java/com/arcadedb/server/http/handler/HttpErrorStatusServerTest.java b/server/src/test/java/com/arcadedb/server/http/handler/HttpErrorStatusServerTest.java index 193f5bb485a..2b9c552182a 100644 --- a/server/src/test/java/com/arcadedb/server/http/handler/HttpErrorStatusServerTest.java +++ b/server/src/test/java/com/arcadedb/server/http/handler/HttpErrorStatusServerTest.java @@ -296,6 +296,12 @@ void rebuildingAnIndexThatDoesNotExistIs400() throws Exception { assertAnswer("REBUILD INDEX Issue11803Nope", 400, SchemaException.class, "Issue11803Nope"); } + @Test + void compactingAnIndexThatDoesNotExistIs400() throws Exception { + // issue #15034: it answered 500 with the SchemaException wrapped in an IndexException + assertAnswer("COMPACT INDEX Issue15034Nope", 400, SchemaException.class, "Issue15034Nope"); + } + @Test void importingASourceThatDoesNotExistIs400() throws Exception { final File missing = new File(System.getProperty("java.io.tmpdir"), "issue11803-" + System.nanoTime() + ".jsonl");