Improve registration error messages

- Don't print the raw IRC message, since we already show the original
  error message
- Avoid double-printing "registration failed"
This commit is contained in:
Simon Ser 2020-08-19 23:35:12 +02:00
parent bdb132ad98
commit 385825d010
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
2 changed files with 20 additions and 5 deletions

View File

@ -32,6 +32,12 @@ var permanentUpstreamCaps = map[string]bool{
"server-time": true, "server-time": true,
} }
type registrationError string
func (err registrationError) Error() string {
return fmt.Sprintf("registration error: %v", string(err))
}
type upstreamChannel struct { type upstreamChannel struct {
Name string Name string
conn *upstreamConn conn *upstreamConn
@ -1357,7 +1363,8 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error {
return fmt.Errorf("fatal server error: %v", text) return fmt.Errorf("fatal server error: %v", text)
case irc.ERR_PASSWDMISMATCH, irc.ERR_ERRONEUSNICKNAME, irc.ERR_NICKNAMEINUSE, irc.ERR_NICKCOLLISION, irc.ERR_UNAVAILRESOURCE, irc.ERR_NOPERMFORHOST, irc.ERR_YOUREBANNEDCREEP: case irc.ERR_PASSWDMISMATCH, irc.ERR_ERRONEUSNICKNAME, irc.ERR_NICKNAMEINUSE, irc.ERR_NICKCOLLISION, irc.ERR_UNAVAILRESOURCE, irc.ERR_NOPERMFORHOST, irc.ERR_YOUREBANNEDCREEP:
if !uc.registered { if !uc.registered {
return fmt.Errorf("registration failed: %v", msg.Params[len(msg.Params)-1]) text := msg.Params[len(msg.Params)-1]
return registrationError(text)
} }
fallthrough fallthrough
default: default:
@ -1526,10 +1533,14 @@ func (uc *upstreamConn) runUntilRegistered() error {
} }
if err := uc.handleMessage(msg); err != nil { if err := uc.handleMessage(msg); err != nil {
if _, ok := err.(registrationError); ok {
return err
} else {
msg.Tags = nil // prevent message tags from cluttering logs msg.Tags = nil // prevent message tags from cluttering logs
return fmt.Errorf("failed to handle message %q: %v", msg, err) return fmt.Errorf("failed to handle message %q: %v", msg, err)
} }
} }
}
for _, command := range uc.network.ConnectCommands { for _, command := range uc.network.ConnectCommands {
m, err := irc.ParseMessage(command) m, err := irc.ParseMessage(command)

View File

@ -140,8 +140,12 @@ func (net *network) run() {
uc.register() uc.register()
if err := uc.runUntilRegistered(); err != nil { if err := uc.runUntilRegistered(); err != nil {
uc.logger.Printf("failed to register: %v", err) text := err.Error()
net.user.events <- eventUpstreamConnectionError{net, fmt.Errorf("failed to register: %v", err)} if regErr, ok := err.(registrationError); ok {
text = string(regErr)
}
uc.logger.Printf("failed to register: %v", text)
net.user.events <- eventUpstreamConnectionError{net, fmt.Errorf("failed to register: %v", text)}
uc.Close() uc.Close()
continue continue
} }