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");