Files
2026-09-21 16:46:55 +08:00

46 lines
971 B
Go

package navicat
import "fmt"
// Error is a tunnel-layer or remote MySQL error. It never includes passwords or tokens.
type Error struct {
Kind string // http, tunnel, mysql
HTTPStatus int
Errno uint32
Message string
}
func (e *Error) Error() string {
if e == nil {
return ""
}
msg := e.Message
if msg == "" {
msg = "unknown error"
}
switch e.Kind {
case "http":
if e.HTTPStatus != 0 {
return fmt.Sprintf("tunnel http %d: %s", e.HTTPStatus, msg)
}
return "tunnel http: " + msg
case "mysql":
return fmt.Sprintf("mysql errno %d: %s", e.Errno, msg)
default:
return fmtErrno(e.Errno, msg)
}
}
func headerError(h Header, httpStatus int) *Error {
kind := "tunnel"
switch h.Errno {
case ErrnoUnsupportedPHP, ErrnoInvalidParams, ErrnoMySQLMissing, ErrnoInvalidToken:
kind = "tunnel"
default:
if h.Errno > 0 {
kind = "mysql"
}
}
return &Error{Kind: kind, HTTPStatus: httpStatus, Errno: h.Errno, Message: h.Message}
}