Browse Source

Give a more helpful error message if a service is created with an unknown user ID

pull/142/head
Kegan Dougal 8 years ago
parent
commit
34ea2d06ce
  1. 5
      src/github.com/matrix-org/go-neb/clients/clients.go
  2. 3
      src/github.com/matrix-org/go-neb/database/schema.go
  3. 3
      src/github.com/matrix-org/go-neb/server/server_test.go

5
src/github.com/matrix-org/go-neb/clients/clients.go

@ -1,6 +1,8 @@
package clients package clients
import ( import (
"database/sql"
"fmt"
"net/http" "net/http"
"strings" "strings"
"sync" "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 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 return
} }

3
src/github.com/matrix-org/go-neb/database/schema.go

@ -4,9 +4,10 @@ import (
"database/sql" "database/sql"
"encoding/json" "encoding/json"
"fmt" "fmt"
"time"
"github.com/matrix-org/go-neb/api" "github.com/matrix-org/go-neb/api"
"github.com/matrix-org/go-neb/types" "github.com/matrix-org/go-neb/types"
"time"
) )
const schemaSQL = ` const schemaSQL = `

3
src/github.com/matrix-org/go-neb/server/server_test.go

@ -10,8 +10,7 @@ func TestProtect(t *testing.T) {
mockWriter := httptest.NewRecorder() mockWriter := httptest.NewRecorder()
mockReq, _ := http.NewRequest("GET", "http://example.com/foo", nil) mockReq, _ := http.NewRequest("GET", "http://example.com/foo", nil)
h := Protect(func(w http.ResponseWriter, req *http.Request) { h := Protect(func(w http.ResponseWriter, req *http.Request) {
var array []string
w.Write([]byte(array[5])) // NPE
panic("oh noes!")
}) })
h(mockWriter, mockReq) h(mockWriter, mockReq)

Loading…
Cancel
Save