implement a string representation for crypto error

This commit is contained in:
Marten Seemann
2019-03-07 09:55:55 +09:00
parent ab47ba1021
commit e5303df419
4 changed files with 22 additions and 5 deletions

View File

@@ -19,7 +19,6 @@ const (
VersionNegotiationError ErrorCode = 0x9
ProtocolViolation ErrorCode = 0xa
InvalidMigration ErrorCode = 0xc
CryptoError ErrorCode = 0x100
)
func (e ErrorCode) Error() string {
@@ -52,9 +51,10 @@ func (e ErrorCode) String() string {
return "PROTOCOL_VIOLATION"
case InvalidMigration:
return "INVALID_MIGRATION"
case CryptoError:
return "CRYPTO_ERROR"
default:
return fmt.Sprintf("unknown error code: %d", e)
if e >= 0x100 && e < 0x200 {
return fmt.Sprintf("CRYPTO_ERROR %d", e-0x100)
}
return fmt.Sprintf("unknown error code: %#x", uint16(e))
}
}