Skip to content

Commit

Permalink
PR(-): Log Server Error On 'Schema Adding Failure'
Browse files Browse the repository at this point in the history
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"}
```
  • Loading branch information
shahzadlone committed Feb 29, 2024
1 parent 5a315d1 commit b73bf47
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions db/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions db/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion db/txn_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
Expand Down

0 comments on commit b73bf47

Please sign in to comment.