Changeset 399 in code for trunk/upstream.go


Ignore:
Timestamp:
Aug 19, 2020, 9:35:12 PM (5 years ago)
Author:
contact
Message:

Improve registration error messages

  • Don't print the raw IRC message, since we already show the original error message
  • Avoid double-printing "registration failed"
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/upstream.go

    r398 r399  
    3131        "multi-prefix":     true,
    3232        "server-time":      true,
     33}
     34
     35type registrationError string
     36
     37func (err registrationError) Error() string {
     38        return fmt.Sprintf("registration error: %v", string(err))
    3339}
    3440
     
    13581364        case irc.ERR_PASSWDMISMATCH, irc.ERR_ERRONEUSNICKNAME, irc.ERR_NICKNAMEINUSE, irc.ERR_NICKCOLLISION, irc.ERR_UNAVAILRESOURCE, irc.ERR_NOPERMFORHOST, irc.ERR_YOUREBANNEDCREEP:
    13591365                if !uc.registered {
    1360                         return fmt.Errorf("registration failed: %v", msg.Params[len(msg.Params)-1])
     1366                        text := msg.Params[len(msg.Params)-1]
     1367                        return registrationError(text)
    13611368                }
    13621369                fallthrough
     
    15271534
    15281535                if err := uc.handleMessage(msg); err != nil {
    1529                         msg.Tags = nil // prevent message tags from cluttering logs
    1530                         return fmt.Errorf("failed to handle message %q: %v", msg, err)
     1536                        if _, ok := err.(registrationError); ok {
     1537                                return err
     1538                        } else {
     1539                                msg.Tags = nil // prevent message tags from cluttering logs
     1540                                return fmt.Errorf("failed to handle message %q: %v", msg, err)
     1541                        }
    15311542                }
    15321543        }
Note: See TracChangeset for help on using the changeset viewer.