mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Postgres datastore errors and cleanup (#579)
* improved postgres datastore error handling * remove excess postgres datastore validation * postgres datastore errors and cleanup
This commit is contained in:
committed by
Seif Lotfy سيف لطفي
parent
3fcdca73a7
commit
690d0d92e4
@@ -159,7 +159,7 @@ func Test(t *testing.T, ds models.Datastore) {
|
||||
}
|
||||
if app != nil {
|
||||
t.Log(buf.String())
|
||||
t.Fatalf("Test RemoveApp: failed to remove the app")
|
||||
t.Fatal("Test RemoveApp: failed to remove the app")
|
||||
}
|
||||
|
||||
// Test update inexistent app
|
||||
|
||||
@@ -47,10 +47,6 @@ type rowScanner interface {
|
||||
Scan(dest ...interface{}) error
|
||||
}
|
||||
|
||||
type rowQuerier interface {
|
||||
QueryRow(query string, args ...interface{}) *sql.Row
|
||||
}
|
||||
|
||||
type PostgresDatastore struct {
|
||||
db *sql.DB
|
||||
}
|
||||
@@ -88,14 +84,6 @@ func (ds *PostgresDatastore) InsertApp(ctx context.Context, app *models.App) (*m
|
||||
var cbyte []byte
|
||||
var err error
|
||||
|
||||
if app == nil {
|
||||
return nil, models.ErrDatastoreEmptyApp
|
||||
}
|
||||
|
||||
if app.Name == "" {
|
||||
return nil, models.ErrDatastoreEmptyAppName
|
||||
}
|
||||
|
||||
if app.Config != nil {
|
||||
cbyte, err = json.Marshal(app.Config)
|
||||
if err != nil {
|
||||
@@ -185,17 +173,18 @@ func (ds *PostgresDatastore) GetApp(ctx context.Context, name string) (*models.A
|
||||
var resName string
|
||||
var config string
|
||||
err := row.Scan(&resName, &config)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, models.ErrAppsNotFound
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res := &models.App{
|
||||
Name: resName,
|
||||
}
|
||||
|
||||
json.Unmarshal([]byte(config), &res.Config)
|
||||
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, models.ErrAppsNotFound
|
||||
}
|
||||
if err := json.Unmarshal([]byte(config), &res.Config); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -209,10 +198,11 @@ func scanApp(scanner rowScanner, app *models.App) error {
|
||||
&app.Name,
|
||||
&configStr,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
json.Unmarshal([]byte(configStr), &app.Config)
|
||||
|
||||
return err
|
||||
return json.Unmarshal([]byte(configStr), &app.Config)
|
||||
}
|
||||
|
||||
func (ds *PostgresDatastore) GetApps(ctx context.Context, filter *models.AppFilter) ([]*models.App, error) {
|
||||
@@ -411,15 +401,18 @@ func scanRoute(scanner rowScanner, route *models.Route) error {
|
||||
&headerStr,
|
||||
&configStr,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if headerStr == "" {
|
||||
return models.ErrRoutesNotFound
|
||||
}
|
||||
|
||||
json.Unmarshal([]byte(headerStr), &route.Headers)
|
||||
json.Unmarshal([]byte(configStr), &route.Config)
|
||||
|
||||
return err
|
||||
if err := json.Unmarshal([]byte(headerStr), &route.Headers); err != nil {
|
||||
return err
|
||||
}
|
||||
return json.Unmarshal([]byte(configStr), &route.Config)
|
||||
}
|
||||
|
||||
func (ds *PostgresDatastore) GetRoute(ctx context.Context, appName, routePath string) (*models.Route, error) {
|
||||
|
||||
Reference in New Issue
Block a user