Skip to content

Commit e0f4aad

Browse files
committed
Clarify error message on graph updates.
1 parent 8864f1d commit e0f4aad

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

internal/database/mariadb.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ func hashRelation(relation knowledge.Relation) uint64 {
258258
func (m *MariaDB) InsertAssets(source string, assets []knowledge.Asset) error {
259259
sourceID, err := m.resolveSourceID(source)
260260
if err != nil {
261-
return fmt.Errorf("Unable to resolve source ID (asset insert): %v", err)
261+
return fmt.Errorf("Unable to resolve source ID of source %s for inserting assets: %v", source, err)
262262
}
263263

264264
tx, err := m.db.Begin()
@@ -303,7 +303,7 @@ func (m *MariaDB) InsertAssets(source string, assets []knowledge.Asset) error {
303303
func (m *MariaDB) InsertRelations(source string, relations []knowledge.Relation) error {
304304
sourceID, err := m.resolveSourceID(source)
305305
if err != nil {
306-
return fmt.Errorf("Unable to resolve source ID (relation insert): %v", err)
306+
return fmt.Errorf("Unable to resolve source ID of source %s for inserting relations: %v", source, err)
307307
}
308308

309309
tx, err := m.db.Begin()
@@ -351,7 +351,7 @@ func (m *MariaDB) InsertRelations(source string, relations []knowledge.Relation)
351351
func (m *MariaDB) RemoveAssets(source string, assets []knowledge.Asset) error {
352352
sourceID, err := m.resolveSourceID(source)
353353
if err != nil {
354-
return fmt.Errorf("Unable to resolve source ID from name %s: %v", source, err)
354+
return fmt.Errorf("Unable to resolve source ID of source %s for removing assets: %v", source, err)
355355
}
356356

357357
tx, err := m.db.Begin()
@@ -392,7 +392,7 @@ func (m *MariaDB) RemoveAssets(source string, assets []knowledge.Asset) error {
392392
func (m *MariaDB) RemoveRelations(source string, relations []knowledge.Relation) error {
393393
sourceID, err := m.resolveSourceID(source)
394394
if err != nil {
395-
return fmt.Errorf("Unable to resolve source ID from name %s: %v", source, err)
395+
return fmt.Errorf("Unable to resolve source ID of source %s for removing relations: %v", source, err)
396396
}
397397

398398
tx, err := m.db.Begin()

internal/handlers/handler_update_graph.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ func PutSchema(registry sources.Registry, graphUpdater *knowledge.GraphUpdater,
6262
}, sem)
6363
}
6464

65-
// PutAsset upsert an asset into the graph of the data source
66-
func PutAsset(registry sources.Registry, graphUpdater *knowledge.GraphUpdater, sem *semaphore.Weighted) http.HandlerFunc {
65+
// PutAssets upsert several assets into the graph of the data source
66+
func PutAssets(registry sources.Registry, graphUpdater *knowledge.GraphUpdater, sem *semaphore.Weighted) http.HandlerFunc {
6767
return handleUpdate(registry, func(source string, body io.Reader) error {
6868
requestBody := client.PutGraphAssetRequestBody{}
6969
if err := json.NewDecoder(body).Decode(&requestBody); err != nil {
@@ -73,14 +73,14 @@ func PutAsset(registry sources.Registry, graphUpdater *knowledge.GraphUpdater, s
7373
// TODO(c.michaud): verify compatibility of the schema with graph updates
7474
err := graphUpdater.InsertAssets(source, requestBody.Assets)
7575
if err != nil {
76-
return fmt.Errorf("Unable to insert asset: %v", err)
76+
return fmt.Errorf("Unable to insert assets: %v", err)
7777
}
7878
return nil
7979
}, sem)
8080
}
8181

82-
// PutRelation upsert a relation into the graph of the data source
83-
func PutRelation(registry sources.Registry, graphUpdater *knowledge.GraphUpdater, sem *semaphore.Weighted) http.HandlerFunc {
82+
// PutRelations upsert multiple relations into the graph of the data source
83+
func PutRelations(registry sources.Registry, graphUpdater *knowledge.GraphUpdater, sem *semaphore.Weighted) http.HandlerFunc {
8484
return handleUpdate(registry, func(source string, body io.Reader) error {
8585
requestBody := client.PutGraphRelationRequestBody{}
8686
if err := json.NewDecoder(body).Decode(&requestBody); err != nil {
@@ -96,8 +96,8 @@ func PutRelation(registry sources.Registry, graphUpdater *knowledge.GraphUpdater
9696
}, sem)
9797
}
9898

99-
// DeleteAsset delete an asset from the graph of the data source
100-
func DeleteAsset(registry sources.Registry, graphUpdater *knowledge.GraphUpdater, sem *semaphore.Weighted) http.HandlerFunc {
99+
// DeleteAssets delete multiple assets from the graph of the data source
100+
func DeleteAssets(registry sources.Registry, graphUpdater *knowledge.GraphUpdater, sem *semaphore.Weighted) http.HandlerFunc {
101101
return handleUpdate(registry, func(source string, body io.Reader) error {
102102
requestBody := client.DeleteGraphAssetRequestBody{}
103103
if err := json.NewDecoder(body).Decode(&requestBody); err != nil {
@@ -107,14 +107,14 @@ func DeleteAsset(registry sources.Registry, graphUpdater *knowledge.GraphUpdater
107107
// TODO(c.michaud): verify compatibility of the schema with graph updates
108108
err := graphUpdater.RemoveAssets(source, requestBody.Assets)
109109
if err != nil {
110-
return fmt.Errorf("Unable to remove asset: %v", err)
110+
return fmt.Errorf("Unable to remove assets: %v", err)
111111
}
112112
return nil
113113
}, sem)
114114
}
115115

116-
// DeleteRelation upsert a relation into the graph of the data source
117-
func DeleteRelation(registry sources.Registry, graphUpdater *knowledge.GraphUpdater, sem *semaphore.Weighted) http.HandlerFunc {
116+
// DeleteRelations remove multiple relations from the graph of the data source
117+
func DeleteRelations(registry sources.Registry, graphUpdater *knowledge.GraphUpdater, sem *semaphore.Weighted) http.HandlerFunc {
118118
return handleUpdate(registry, func(source string, body io.Reader) error {
119119
requestBody := client.DeleteGraphRelationRequestBody{}
120120
if err := json.NewDecoder(body).Decode(&requestBody); err != nil {

internal/knowledge/graph_updater.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,31 +50,31 @@ func (sl *GraphUpdater) UpdateSchema(source string, sg schema.SchemaGraph) error
5050
// InsertAssets insert multiple assets in the graph of the data source
5151
func (sl *GraphUpdater) InsertAssets(source string, assets []Asset) error {
5252
if err := sl.graphDB.InsertAssets(source, assets); err != nil {
53-
return fmt.Errorf("Unable to insert assets %v from source %s: %v", assets, source, err)
53+
return fmt.Errorf("Unable to insert assets from source %s: %v", source, err)
5454
}
5555
return nil
5656
}
5757

5858
// InsertRelations insert multiple relations in the graph of the data source
5959
func (sl *GraphUpdater) InsertRelations(source string, relations []Relation) error {
6060
if err := sl.graphDB.InsertRelations(source, relations); err != nil {
61-
return fmt.Errorf("Unable to insert relations %v from source %s: %v", relations, source, err)
61+
return fmt.Errorf("Unable to insert relations from source %s: %v", source, err)
6262
}
6363
return nil
6464
}
6565

6666
// RemoveAssets remove multiple assets from the graph of the data source
6767
func (sl *GraphUpdater) RemoveAssets(source string, assets []Asset) error {
6868
if err := sl.graphDB.RemoveAssets(source, assets); err != nil {
69-
return fmt.Errorf("Unable to remove assets %v from source %s: %v", assets, source, err)
69+
return fmt.Errorf("Unable to remove assets from source %s: %v", source, err)
7070
}
7171
return nil
7272
}
7373

7474
// RemoveRelations remove multiple relations from the graph of the data source
7575
func (sl *GraphUpdater) RemoveRelations(source string, relations []Relation) error {
7676
if err := sl.graphDB.RemoveRelations(source, relations); err != nil {
77-
return fmt.Errorf("Unable to remove relation %v from source %s: %v", relations, source, err)
77+
return fmt.Errorf("Unable to remove relations from source %s: %v", source, err)
7878
}
7979
return nil
8080
}

internal/server/server.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,10 @@ func StartServer(listenInterface string,
219219
sem := semaphore.NewWeighted(concurrency)
220220

221221
r.HandleFunc("/api/graph/schema", handlers.PutSchema(sourcesRegistry, graphUpdater, sem)).Methods("PUT")
222-
r.HandleFunc("/api/graph/assets", handlers.PutAsset(sourcesRegistry, graphUpdater, sem)).Methods("PUT")
223-
r.HandleFunc("/api/graph/assets", handlers.DeleteAsset(sourcesRegistry, graphUpdater, sem)).Methods("DELETE")
224-
r.HandleFunc("/api/graph/relations", handlers.PutRelation(sourcesRegistry, graphUpdater, sem)).Methods("PUT")
225-
r.HandleFunc("/api/graph/relations", handlers.DeleteRelation(sourcesRegistry, graphUpdater, sem)).Methods("DELETE")
222+
r.HandleFunc("/api/graph/assets", handlers.PutAssets(sourcesRegistry, graphUpdater, sem)).Methods("PUT")
223+
r.HandleFunc("/api/graph/assets", handlers.DeleteAssets(sourcesRegistry, graphUpdater, sem)).Methods("DELETE")
224+
r.HandleFunc("/api/graph/relations", handlers.PutRelations(sourcesRegistry, graphUpdater, sem)).Methods("PUT")
225+
r.HandleFunc("/api/graph/relations", handlers.DeleteRelations(sourcesRegistry, graphUpdater, sem)).Methods("DELETE")
226226

227227
r.HandleFunc("/api/query", postQueryHandler).Methods("POST")
228228
r.PathPrefix("/").Handler(http.FileServer(http.Dir("./web/build/")))

0 commit comments

Comments
 (0)