neo4j-contrib / neo4j-apoc-procedures

Awesome Procedures On Cypher for Neo4j - codenamed "apoc"                     If you like it, please ★ above ⇧            
https://neo4j.com/labs/apoc
Apache License 2.0
1.71k stars 493 forks source link

Better error messaging with vectordb procedures #4109

Open vga91 opened 4 months ago

vga91 commented 4 months ago

The following procedure should return the root cause (i.e. the collection already exists):

Bildschirmfoto 2024-06-21 um 15 05 03 (1)

Procedure errors to handle and improve:

vga91 commented 4 months ago

Currently, it does not seem possible to solve the issue by acting on APOC Extended, it would be necessary to modify APOC Core.

The following solution (i.e. the one provided in the internal APOC core Trello with id G2oExgfb) would solve the issue:

// placed in StreamCollection.UrlStreamConnection class by replacing the present method

        @Override
        public InputStream getInputStream() throws IOException {
            if (con instanceof HttpURLConnection httpConn && httpConn.getResponseCode() >= 400)
            {
                // return ErrorStream as a RuntimeException
                String errMsg = new String(httpConn.getErrorStream().readAllBytes());
                throw new RuntimeException("Error during HTTP call:\n" + errMsg);
            }

            return toLimitedIStream(con.getInputStream(), getLength());
        }

By returning the following output in case of an existing collection:

org.neo4j.graphdb.QueryExecutionException:
Failed to invoke procedure `apoc.vectordb.weaviate.createCollection`: Caused by: java.lang.RuntimeException: Error during HTTP call:
{"error":[{"message":"class name \"TestCollection\" already exists"}]}

Examples of test case to update after the above fixes: https://github.com/neo4j-contrib/neo4j-apoc-procedures/commit/99e6025f9a2462d39f48637c42b3cb60647f9441