From 34ea2d06ce61e5af5652a75f3e2a7bb3f64e37c9 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Fri, 9 Dec 2016 13:56:43 +0000 Subject: [PATCH] Give a more helpful error message if a service is created with an unknown user ID --- src/github.com/matrix-org/go-neb/clients/clients.go | 5 +++++ src/github.com/matrix-org/go-neb/database/schema.go | 3 ++- src/github.com/matrix-org/go-neb/server/server_test.go | 3 +-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/github.com/matrix-org/go-neb/clients/clients.go b/src/github.com/matrix-org/go-neb/clients/clients.go index 842e7f2..1927f64 100644 --- a/src/github.com/matrix-org/go-neb/clients/clients.go +++ b/src/github.com/matrix-org/go-neb/clients/clients.go @@ -1,6 +1,8 @@ package clients import ( + "database/sql" + "fmt" "net/http" "strings" "sync" @@ -94,6 +96,9 @@ func (c *Clients) loadClientFromDB(userID string) (entry clientEntry, err error) } if entry.config, err = c.db.LoadMatrixClientConfig(userID); err != nil { + if err == sql.ErrNoRows { + err = fmt.Errorf("client with user ID %s does not exist", userID) + } return } diff --git a/src/github.com/matrix-org/go-neb/database/schema.go b/src/github.com/matrix-org/go-neb/database/schema.go index 7e3a30f..9a9fc51 100644 --- a/src/github.com/matrix-org/go-neb/database/schema.go +++ b/src/github.com/matrix-org/go-neb/database/schema.go @@ -4,9 +4,10 @@ import ( "database/sql" "encoding/json" "fmt" + "time" + "github.com/matrix-org/go-neb/api" "github.com/matrix-org/go-neb/types" - "time" ) const schemaSQL = ` diff --git a/src/github.com/matrix-org/go-neb/server/server_test.go b/src/github.com/matrix-org/go-neb/server/server_test.go index 920d0ae..b9afb12 100644 --- a/src/github.com/matrix-org/go-neb/server/server_test.go +++ b/src/github.com/matrix-org/go-neb/server/server_test.go @@ -10,8 +10,7 @@ func TestProtect(t *testing.T) { mockWriter := httptest.NewRecorder() mockReq, _ := http.NewRequest("GET", "http://example.com/foo", nil) h := Protect(func(w http.ResponseWriter, req *http.Request) { - var array []string - w.Write([]byte(array[5])) // NPE + panic("oh noes!") }) h(mockWriter, mockReq)