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
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
}

3
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 = `

3
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)

Loading…
Cancel
Save