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,
}
type registrationError string
func (err registrationError) Error() string {
return fmt.Sprintf("registration error: %v", string(err))
}
type upstreamChannel struct {
Name string
conn *upstreamConn
@ -1357,7 +1363,8 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error {
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:
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
default:
@ -1526,10 +1533,14 @@ func (uc *upstreamConn) runUntilRegistered() error {
}
if err := uc.handleMessage(msg); err != nil {
if _, ok := err.(registrationError); ok {
return err
} else {
msg.Tags = nil // prevent message tags from cluttering logs
return fmt.Errorf("failed to handle message %q: %v", msg, err)
}
}
}
for _, command := range uc.network.ConnectCommands {
m, err := irc.ParseMessage(command)

View file

@ -140,8 +140,12 @@ func (net *network) run() {
uc.register()
if err := uc.runUntilRegistered(); err != nil {
uc.logger.Printf("failed to register: %v", err)
net.user.events <- eventUpstreamConnectionError{net, fmt.Errorf("failed to register: %v", err)}
text := err.Error()
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()
continue
}