From b73bf47ab74c52743a8fce9e2638c31903fff449 Mon Sep 17 00:00:00 2001 From: Shahzad Lone Date: Wed, 28 Feb 2024 20:32:11 -0500 Subject: [PATCH] PR(-): Log Server Error On 'Schema Adding Failure' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now will log the error on the server like so: ``` 2024-02-28T20:30:25.154-0500, INFO, net, Created LibP2P host, {"PeerId": "12D3KooWJMRCnMLvppLUaAZwzPsWPhfk6w7wmyPdu4wUEnUVUUVP", "Address": ["/ip4/127.0.0.1/tcp/9171"]} 2024-02-28T20:30:25.156-0500, INFO, cli, Starting DefraDB 2024-02-28T20:30:25.156-0500, INFO, net, Starting internal broadcaster for pubsub network 2024-02-28T20:30:26.975-0500, ERROR, db, could not add schema, {"Error": "collection already exists"} 2024-02-28T20:30:26.975-0500, INFO, http, Request, {"Method": "POST", "Path": "/api/v0/schema", "Status": 400, "LengthBytes": 38, "ElapsedTime": "526.443┬╡s"} ``` --- db/errors.go | 1 + db/schema.go | 1 + db/txn_db.go | 8 +++++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/db/errors.go b/db/errors.go index 12fa3a5661..7d4496b156 100644 --- a/db/errors.go +++ b/db/errors.go @@ -23,6 +23,7 @@ const ( errDocVerification string = "the document verification failed" errAddingP2PCollection string = "cannot add collection ID" errRemovingP2PCollection string = "cannot remove collection ID" + errCouldNotAddSchema string = "could not add schema" errAddCollectionWithPatch string = "unknown collection, adding collections via patch is not supported" errCollectionIDDoesntMatch string = "CollectionID does not match existing" errSchemaRootDoesntMatch string = "SchemaRoot does not match existing" diff --git a/db/schema.go b/db/schema.go index c921796eeb..205c25a656 100644 --- a/db/schema.go +++ b/db/schema.go @@ -49,6 +49,7 @@ func (db *db) addSchema( if err != nil { return nil, err } + returnDescriptions := make([]client.CollectionDescription, len(newDefinitions)) for i, definition := range newDefinitions { col, err := db.createCollection(ctx, txn, definition) diff --git a/db/txn_db.go b/db/txn_db.go index 60032290d6..895c13f50d 100644 --- a/db/txn_db.go +++ b/db/txn_db.go @@ -186,6 +186,7 @@ func (db *implicitTxnDB) AddSchema(ctx context.Context, schemaString string) ([] cols, err := db.addSchema(ctx, txn, schemaString) if err != nil { + log.ErrorE(ctx, errCouldNotAddSchema, err) return nil, err } @@ -201,7 +202,12 @@ func (db *implicitTxnDB) AddSchema(ctx context.Context, schemaString string) ([] // All schema types provided must not exist prior to calling this, and they may not reference existing // types previously defined. func (db *explicitTxnDB) AddSchema(ctx context.Context, schemaString string) ([]client.CollectionDescription, error) { - return db.addSchema(ctx, db.txn, schemaString) + cols, err := db.addSchema(ctx, db.txn, schemaString) + if err != nil { + log.ErrorE(ctx, errCouldNotAddSchema, err) + return nil, err + } + return cols, nil } // PatchSchema takes the given JSON patch string and applies it to the set of CollectionDescriptions