throw more detailed error when base resource type exists
@@ -2,13 +2,20 @@ package dbng
import (
"database/sql"
- "errors"
+ "fmt"
sq "github.com/Masterminds/squirrel"
"github.com/lib/pq"
)
-var ErrWorkerBaseResourceTypeAlreadyExists = errors.New("worker base resource type already exists")
+type WorkerBaseResourceTypeAlreadyExistsError struct {
+ WorkerName string
+ BaseResourceTypeName string
+}
+
+func (e WorkerBaseResourceTypeAlreadyExistsError) Error() string {
+ return fmt.Sprintf("worker '%s' base resource type '%s' already exists", e.WorkerName, e.BaseResourceTypeName)
+}
// base_resource_types: <- gced referenced by 0 workers
// | id | type | image | version |
@@ -98,7 +105,10 @@ func (wrt WorkerResourceType) create(tx Tx, usedBaseResourceType *UsedBaseResour
Scan(&id)
if err != nil {
if pqErr, ok := err.(*pq.Error); ok && pqErr.Code.Name() == "unique_violation" {
- return nil, ErrWorkerBaseResourceTypeAlreadyExists
+ return nil, WorkerBaseResourceTypeAlreadyExistsError{
+ WorkerName: wrt.Worker.Name(),
+ BaseResourceTypeName: usedBaseResourceType.Name,
+ }
}
return nil, err
