mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-12 17:33:09 -06:00
Fix new linting issues
This commit is contained in:
parent
9e9a337c68
commit
89a7d094da
|
|
@ -281,7 +281,7 @@ func hashPassword(plaintext string) (hash string, err error) {
|
|||
|
||||
// Err3PIDInUse is the error returned when trying to save an association involving
|
||||
// a third-party identifier which is already associated to a local user.
|
||||
var Err3PIDInUse = errors.New("This third-party identifier is already in use")
|
||||
var Err3PIDInUse = errors.New("this third-party identifier is already in use")
|
||||
|
||||
// SaveThreePIDAssociation saves the association between a third party identifier
|
||||
// and a local Matrix user (identified by the user's ID's local part).
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ func (p *SyncAPIProducer) SendData(userID string, roomID string, dataType string
|
|||
return err
|
||||
}
|
||||
|
||||
m.Topic = string(p.Topic)
|
||||
m.Topic = p.Topic
|
||||
m.Key = sarama.StringEncoder(userID)
|
||||
m.Value = sarama.ByteEncoder(value)
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ func (p *UserUpdateProducer) SendUpdate(
|
|||
var update profileUpdate
|
||||
var m sarama.ProducerMessage
|
||||
|
||||
m.Topic = string(p.Topic)
|
||||
m.Topic = p.Topic
|
||||
m.Key = sarama.StringEncoder(userID)
|
||||
|
||||
update = profileUpdate{
|
||||
|
|
|
|||
|
|
@ -725,19 +725,19 @@ func isValidMacLogin(
|
|||
|
||||
// Check that shared secret registration isn't disabled.
|
||||
if cfg.Matrix.RegistrationSharedSecret == "" {
|
||||
return false, errors.New("Shared secret registration is disabled")
|
||||
return false, errors.New("shared secret registration is disabled")
|
||||
}
|
||||
|
||||
// Double check that username/password don't contain the HMAC delimiters. We should have
|
||||
// already checked this.
|
||||
if strings.Contains(username, "\x00") {
|
||||
return false, errors.New("Username contains invalid character")
|
||||
return false, errors.New("username contains invalid character")
|
||||
}
|
||||
if strings.Contains(password, "\x00") {
|
||||
return false, errors.New("Password contains invalid character")
|
||||
return false, errors.New("password contains invalid character")
|
||||
}
|
||||
if sharedSecret == "" {
|
||||
return false, errors.New("Shared secret registration is disabled")
|
||||
return false, errors.New("shared secret registration is disabled")
|
||||
}
|
||||
|
||||
adminString := "notadmin"
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ func CreateSession(
|
|||
|
||||
// Error if the status isn't OK
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return "", fmt.Errorf("Could not create a session on the server %s", req.IDServer)
|
||||
return "", fmt.Errorf("could not create a session on the server %s", req.IDServer)
|
||||
}
|
||||
|
||||
// Extract the SID from the response and return it
|
||||
|
|
@ -168,7 +168,7 @@ func PublishAssociation(creds Credentials, userID string, cfg config.Dendrite) e
|
|||
|
||||
// Error if the status isn't OK
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return fmt.Errorf("Could not publish the association on the server %s", creds.IDServer)
|
||||
return fmt.Errorf("could not publish the association on the server %s", creds.IDServer)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -31,11 +31,11 @@ func ParseUsernameParam(usernameParam string, expectedServerName *gomatrixserver
|
|||
lp, domain, err := gomatrixserverlib.SplitID('@', usernameParam)
|
||||
|
||||
if err != nil {
|
||||
return "", errors.New("Invalid username")
|
||||
return "", errors.New("invalid username")
|
||||
}
|
||||
|
||||
if expectedServerName != nil && domain != *expectedServerName {
|
||||
return "", errors.New("User ID does not belong to this server")
|
||||
return "", errors.New("user ID does not belong to this server")
|
||||
}
|
||||
|
||||
localpart = lp
|
||||
|
|
|
|||
|
|
@ -139,6 +139,6 @@ func writeEvent(event gomatrixserverlib.Event) {
|
|||
panic(err)
|
||||
}
|
||||
} else {
|
||||
panic(fmt.Errorf("Format %q is not valid, must be %q or %q", format, "InputRoomEvent", "Event"))
|
||||
panic(fmt.Errorf("format %q is not valid, must be %q or %q", *format, "InputRoomEvent", "Event"))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ func runAndReadFromTopic(runCmd *exec.Cmd, readyURL string, doInput func(), topi
|
|||
}()
|
||||
go func() {
|
||||
time.Sleep(timeout)
|
||||
done <- result{nil, fmt.Errorf("Timeout reading %d messages from topic %q", count, topic)}
|
||||
done <- result{nil, fmt.Errorf("timeout reading %d messages from topic %q", count, topic)}
|
||||
}()
|
||||
|
||||
// Poll the HTTP listener of the process waiting for it to be ready to receive requests.
|
||||
|
|
@ -266,12 +266,12 @@ func testRoomserver(input []string, wantOutput []string, checkQueries func(api.R
|
|||
}
|
||||
|
||||
if len(wantOutput) != len(gotOutput) {
|
||||
panic(fmt.Errorf("Wanted %d lines of output got %d lines", len(wantOutput), len(gotOutput)))
|
||||
panic(fmt.Errorf("wanted %d lines of output got %d lines", len(wantOutput), len(gotOutput)))
|
||||
}
|
||||
|
||||
for i := range wantOutput {
|
||||
if !equalJSON(wantOutput[i], gotOutput[i]) {
|
||||
panic(fmt.Errorf("Wanted %q at index %d got %q", wantOutput[i], i, gotOutput[i]))
|
||||
panic(fmt.Errorf("wanted %q at index %d got %q", wantOutput[i], i, gotOutput[i]))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -407,13 +407,13 @@ func main() {
|
|||
panic(err)
|
||||
}
|
||||
if !response.RoomExists {
|
||||
panic(fmt.Errorf(`Wanted room "!HCXfdvrfksxuYnIFiJ:matrix.org" to exist`))
|
||||
panic(fmt.Errorf(`wanted room "!HCXfdvrfksxuYnIFiJ:matrix.org" to exist`))
|
||||
}
|
||||
if len(response.LatestEvents) != 1 || response.LatestEvents[0].EventID != "$1463671339126270PnVwC:matrix.org" {
|
||||
panic(fmt.Errorf(`Wanted "$1463671339126270PnVwC:matrix.org" to be the latest event got %#v`, response.LatestEvents))
|
||||
panic(fmt.Errorf(`wanted "$1463671339126270PnVwC:matrix.org" to be the latest event got %#v`, response.LatestEvents))
|
||||
}
|
||||
if len(response.StateEvents) != 1 || response.StateEvents[0].EventID() != "$1463671339126270PnVwC:matrix.org" {
|
||||
panic(fmt.Errorf(`Wanted "$1463671339126270PnVwC:matrix.org" to be the state event got %#v`, response.StateEvents))
|
||||
panic(fmt.Errorf(`wanted "$1463671339126270PnVwC:matrix.org" to be the state event got %#v`, response.StateEvents))
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -547,8 +547,8 @@ func (config *Dendrite) checkListen(configErrs *configErrors) {
|
|||
// checkLogging verifies the parameters logging.* are valid.
|
||||
func (config *Dendrite) checkLogging(configErrs *configErrors) {
|
||||
for _, logrusHook := range config.Logging {
|
||||
checkNotEmpty(configErrs, "logging.type", string(logrusHook.Type))
|
||||
checkNotEmpty(configErrs, "logging.level", string(logrusHook.Level))
|
||||
checkNotEmpty(configErrs, "logging.type", logrusHook.Type)
|
||||
checkNotEmpty(configErrs, "logging.level", logrusHook.Level)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ import (
|
|||
|
||||
// ErrRoomNoExists is returned when trying to lookup the state of a room that
|
||||
// doesn't exist
|
||||
var ErrRoomNoExists = errors.New("Room does not exist")
|
||||
var ErrRoomNoExists = errors.New("room does not exist")
|
||||
|
||||
// BuildEvent builds a Matrix event using the event builder and roomserver query
|
||||
// API client provided. If also fills roomserver query API response (if provided)
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ func (r *Request) Do() (err error) {
|
|||
Timeout: 5 * time.Second,
|
||||
Transport: &http.Transport{
|
||||
TLSClientConfig: &tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
InsecureSkipVerify: true, // nolint: gas
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,10 +35,10 @@ import (
|
|||
// For example, if Base64Hash is 'qwerty', the path will be 'q/w/erty/file'.
|
||||
func GetPathFromBase64Hash(base64Hash types.Base64Hash, absBasePath config.Path) (string, error) {
|
||||
if len(base64Hash) < 3 {
|
||||
return "", fmt.Errorf("Invalid filePath (Base64Hash too short - min 3 characters): %q", base64Hash)
|
||||
return "", fmt.Errorf("invalid filePath (Base64Hash too short - min 3 characters): %q", base64Hash)
|
||||
}
|
||||
if len(base64Hash) > 255 {
|
||||
return "", fmt.Errorf("Invalid filePath (Base64Hash too long - max 255 characters): %q", base64Hash)
|
||||
return "", fmt.Errorf("invalid filePath (Base64Hash too long - max 255 characters): %q", base64Hash)
|
||||
}
|
||||
|
||||
filePath, err := filepath.Abs(filepath.Join(
|
||||
|
|
@ -49,14 +49,14 @@ func GetPathFromBase64Hash(base64Hash types.Base64Hash, absBasePath config.Path)
|
|||
"file",
|
||||
))
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Unable to construct filePath: %q", err)
|
||||
return "", fmt.Errorf("unable to construct filePath: %q", err)
|
||||
}
|
||||
|
||||
// check if the absolute absBasePath is a prefix of the absolute filePath
|
||||
// if so, no directory escape has occurred and the filePath is valid
|
||||
// Note: absBasePath is already absolute
|
||||
if !strings.HasPrefix(filePath, string(absBasePath)) {
|
||||
return "", fmt.Errorf("Invalid filePath (not within absBasePath %v): %v", absBasePath, filePath)
|
||||
return "", fmt.Errorf("invalid filePath (not within absBasePath %v): %v", absBasePath, filePath)
|
||||
}
|
||||
|
||||
return filePath, nil
|
||||
|
|
@ -143,11 +143,11 @@ func moveFile(src types.Path, dst types.Path) error {
|
|||
|
||||
err := os.MkdirAll(dstDir, 0770)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to make directory: %q", err)
|
||||
return fmt.Errorf("failed to make directory: %q", err)
|
||||
}
|
||||
err = os.Rename(string(src), string(dst))
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to move directory: %q", err)
|
||||
return fmt.Errorf("failed to move directory: %q", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
@ -155,11 +155,11 @@ func moveFile(src types.Path, dst types.Path) error {
|
|||
func createTempFileWriter(absBasePath config.Path) (*bufio.Writer, *os.File, types.Path, error) {
|
||||
tmpDir, err := createTempDir(absBasePath)
|
||||
if err != nil {
|
||||
return nil, nil, "", fmt.Errorf("Failed to create temp dir: %q", err)
|
||||
return nil, nil, "", fmt.Errorf("failed to create temp dir: %q", err)
|
||||
}
|
||||
writer, tmpFile, err := createFileWriter(tmpDir)
|
||||
if err != nil {
|
||||
return nil, nil, "", fmt.Errorf("Failed to create file writer: %q", err)
|
||||
return nil, nil, "", fmt.Errorf("failed to create file writer: %q", err)
|
||||
}
|
||||
return writer, tmpFile, tmpDir, nil
|
||||
}
|
||||
|
|
@ -168,11 +168,11 @@ func createTempFileWriter(absBasePath config.Path) (*bufio.Writer, *os.File, typ
|
|||
func createTempDir(baseDirectory config.Path) (types.Path, error) {
|
||||
baseTmpDir := filepath.Join(string(baseDirectory), "tmp")
|
||||
if err := os.MkdirAll(baseTmpDir, 0770); err != nil {
|
||||
return "", fmt.Errorf("Failed to create base temp dir: %v", err)
|
||||
return "", fmt.Errorf("failed to create base temp dir: %v", err)
|
||||
}
|
||||
tmpDir, err := ioutil.TempDir(baseTmpDir, "")
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Failed to create temp dir: %v", err)
|
||||
return "", fmt.Errorf("failed to create temp dir: %v", err)
|
||||
}
|
||||
return types.Path(tmpDir), nil
|
||||
}
|
||||
|
|
@ -184,7 +184,7 @@ func createFileWriter(directory types.Path) (*bufio.Writer, *os.File, error) {
|
|||
filePath := filepath.Join(string(directory), "content")
|
||||
file, err := os.Create(filePath)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("Failed to create file: %v", err)
|
||||
return nil, nil, fmt.Errorf("failed to create file: %v", err)
|
||||
}
|
||||
|
||||
return bufio.NewWriter(file), file, nil
|
||||
|
|
|
|||
|
|
@ -387,8 +387,8 @@ func (r *downloadRequest) getThumbnailFile(
|
|||
"FileSizeBytes": thumbnail.MediaMetadata.FileSizeBytes,
|
||||
"ContentType": thumbnail.MediaMetadata.ContentType,
|
||||
})
|
||||
thumbPath := string(thumbnailer.GetThumbnailPath(types.Path(filePath), thumbnail.ThumbnailSize))
|
||||
thumbFile, err := os.Open(string(thumbPath))
|
||||
thumbPath := string(thumbnailer.GetThumbnailPath(filePath, thumbnail.ThumbnailSize))
|
||||
thumbFile, err := os.Open(thumbPath)
|
||||
if err != nil {
|
||||
thumbFile.Close() // nolint: errcheck
|
||||
return nil, nil, errors.Wrap(err, "failed to open file")
|
||||
|
|
@ -661,7 +661,7 @@ func (r *downloadRequest) fetchRemoteFile(
|
|||
// It's possible the bytesWritten to the temporary file is different to the reported Content-Length from the remote
|
||||
// request's response. bytesWritten is therefore used as it is what would be sent to clients when reading from the local
|
||||
// file.
|
||||
r.MediaMetadata.FileSizeBytes = types.FileSizeBytes(bytesWritten)
|
||||
r.MediaMetadata.FileSizeBytes = bytesWritten
|
||||
r.MediaMetadata.Base64Hash = hash
|
||||
|
||||
// The database is the source of truth so we need to have moved the file first
|
||||
|
|
@ -674,7 +674,7 @@ func (r *downloadRequest) fetchRemoteFile(
|
|||
// Continue on to store the metadata in the database
|
||||
}
|
||||
|
||||
return types.Path(finalPath), duplicate, nil
|
||||
return finalPath, duplicate, nil
|
||||
}
|
||||
|
||||
func (r *downloadRequest) createRemoteRequest(
|
||||
|
|
|
|||
|
|
@ -269,7 +269,7 @@ func (s *publicRoomsStatements) updateRoomAttribute(
|
|||
case bool, string:
|
||||
value = attrValue
|
||||
default:
|
||||
return errors.New("Unsupported attribute type, must be bool, string or []string")
|
||||
return errors.New("unsupported attribute type, must be bool, string or []string")
|
||||
}
|
||||
|
||||
_, err := stmt.ExecContext(ctx, value, roomID)
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ func LoadStateAtSnapshot(
|
|||
if !ok {
|
||||
// This should only get hit if the database is corrupt.
|
||||
// It should be impossible for an event to reference a NID that doesn't exist
|
||||
panic(fmt.Errorf("Corrupt DB: Missing state block numeric ID %d", stateBlockNID))
|
||||
panic(fmt.Errorf("corrupt DB: Missing state block numeric ID %d", stateBlockNID))
|
||||
}
|
||||
fullState = append(fullState, entries...)
|
||||
}
|
||||
|
|
@ -167,7 +167,7 @@ func LoadCombinedStateAfterEvents(
|
|||
if !ok {
|
||||
// This should only get hit if the database is corrupt.
|
||||
// It should be impossible for an event to reference a NID that doesn't exist
|
||||
panic(fmt.Errorf("Corrupt DB: Missing state snapshot numeric ID %d", prevState.BeforeStateSnapshotNID))
|
||||
panic(fmt.Errorf("corrupt DB: Missing state snapshot numeric ID %d", prevState.BeforeStateSnapshotNID))
|
||||
}
|
||||
|
||||
// Combine all the state entries for this snapshot.
|
||||
|
|
@ -178,7 +178,7 @@ func LoadCombinedStateAfterEvents(
|
|||
if !ok {
|
||||
// This should only get hit if the database is corrupt.
|
||||
// It should be impossible for an event to reference a NID that doesn't exist
|
||||
panic(fmt.Errorf("Corrupt DB: Missing state block numeric ID %d", stateBlockNID))
|
||||
panic(fmt.Errorf("corrupt DB: Missing state block numeric ID %d", stateBlockNID))
|
||||
}
|
||||
fullState = append(fullState, entries...)
|
||||
}
|
||||
|
|
@ -754,7 +754,7 @@ func resolveConflicts(
|
|||
for _, resolvedEvent := range resolvedEvents {
|
||||
entry, ok := eventIDMap[resolvedEvent.EventID()]
|
||||
if !ok {
|
||||
panic(fmt.Errorf("Missing state entry for event ID %q", resolvedEvent.EventID()))
|
||||
panic(fmt.Errorf("missing state entry for event ID %q", resolvedEvent.EventID()))
|
||||
}
|
||||
notConflicted = append(notConflicted, entry)
|
||||
}
|
||||
|
|
@ -826,7 +826,7 @@ func loadStateEvents(
|
|||
for i := range entries {
|
||||
event, ok := eventMap(events).lookup(entries[i].EventNID)
|
||||
if !ok {
|
||||
panic(fmt.Errorf("Corrupt DB: Missing event numeric ID %d", entries[i].EventNID))
|
||||
panic(fmt.Errorf("corrupt DB: Missing event numeric ID %d", entries[i].EventNID))
|
||||
}
|
||||
result[i] = event.Event
|
||||
eventIDMap[event.Event.EventID()] = entries[i]
|
||||
|
|
|
|||
|
|
@ -148,7 +148,7 @@ func (s *OutputRoomEventConsumer) onNewRoomEvent(
|
|||
}).Panicf("roomserver output log: write event failure")
|
||||
return nil
|
||||
}
|
||||
s.notifier.OnNewEvent(&ev, "", types.StreamPosition(syncStreamPos))
|
||||
s.notifier.OnNewEvent(&ev, "", syncStreamPos)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ import (
|
|||
"github.com/matrix-org/dendrite/syncapi/routing"
|
||||
"github.com/matrix-org/dendrite/syncapi/storage"
|
||||
"github.com/matrix-org/dendrite/syncapi/sync"
|
||||
"github.com/matrix-org/dendrite/syncapi/types"
|
||||
)
|
||||
|
||||
// SetupSyncAPIComponent sets up and registers HTTP handlers for the SyncAPI
|
||||
|
|
@ -49,7 +48,7 @@ func SetupSyncAPIComponent(
|
|||
logrus.WithError(err).Panicf("failed to get stream position")
|
||||
}
|
||||
|
||||
notifier := sync.NewNotifier(types.StreamPosition(pos))
|
||||
notifier := sync.NewNotifier(pos)
|
||||
err = notifier.Load(context.Background(), syncDB)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Panicf("failed to start notifier")
|
||||
|
|
|
|||
Loading…
Reference in a new issue