refactor: rename package errors to zerrors (#7039)

* chore: rename package errors to zerrors

* rename package errors to gerrors

* fix error related linting issues

* fix zitadel error assertion

* fix gosimple linting issues

* fix deprecated linting issues

* resolve gci linting issues

* fix import structure

---------

Co-authored-by: Elio Bischof <elio@zitadel.com>
This commit is contained in:
Tim Möhlmann
2023-12-08 16:30:55 +02:00
committed by GitHub
parent ddbea119f1
commit f680dd934d
798 changed files with 5809 additions and 5813 deletions

View File

@@ -11,9 +11,9 @@ import (
"github.com/k3a/html2text"
"github.com/zitadel/logging"
"github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/notification/channels"
"github.com/zitadel/zitadel/internal/notification/messages"
"github.com/zitadel/zitadel/internal/zerrors"
)
func InitFSChannel(config Config) (channels.NotificationChannel, error) {
@@ -44,7 +44,7 @@ func InitFSChannel(config Config) (channels.NotificationChannel, error) {
case *messages.JSON:
fileName = "message.json"
default:
return errors.ThrowUnimplementedf(nil, "NOTIF-6f9a1", "filesystem provider doesn't support message type %T", message)
return zerrors.ThrowUnimplementedf(nil, "NOTIF-6f9a1", "filesystem provider doesn't support message type %T", message)
}
return os.WriteFile(filepath.Join(config.Path, fileName), []byte(content), 0666)

View File

@@ -8,9 +8,9 @@ import (
"github.com/zitadel/logging"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/notification/channels"
"github.com/zitadel/zitadel/internal/notification/messages"
"github.com/zitadel/zitadel/internal/zerrors"
)
var _ channels.NotificationChannel = (*Email)(nil)
@@ -41,22 +41,22 @@ func (email *Email) HandleMessage(message channels.Message) error {
defer email.smtpClient.Close()
emailMsg, ok := message.(*messages.Email)
if !ok {
return caos_errs.ThrowInternal(nil, "EMAIL-s8JLs", "message is not EmailMessage")
return zerrors.ThrowInternal(nil, "EMAIL-s8JLs", "message is not EmailMessage")
}
if emailMsg.Content == "" || emailMsg.Subject == "" || len(emailMsg.Recipients) == 0 {
return caos_errs.ThrowInternalf(nil, "EMAIL-zGemZ", "subject, recipients and content must be set but got subject %s, recipients length %d and content length %d", emailMsg.Subject, len(emailMsg.Recipients), len(emailMsg.Content))
return zerrors.ThrowInternalf(nil, "EMAIL-zGemZ", "subject, recipients and content must be set but got subject %s, recipients length %d and content length %d", emailMsg.Subject, len(emailMsg.Recipients), len(emailMsg.Content))
}
emailMsg.SenderEmail = email.senderAddress
emailMsg.SenderName = email.senderName
emailMsg.ReplyToAddress = email.replyToAddress
// To && From
if err := email.smtpClient.Mail(emailMsg.SenderEmail); err != nil {
return caos_errs.ThrowInternalf(err, "EMAIL-s3is3", "could not set sender: %v", emailMsg.SenderEmail)
return zerrors.ThrowInternalf(err, "EMAIL-s3is3", "could not set sender: %v", emailMsg.SenderEmail)
}
for _, recp := range append(append(emailMsg.Recipients, emailMsg.CC...), emailMsg.BCC...) {
if err := email.smtpClient.Rcpt(recp); err != nil {
return caos_errs.ThrowInternalf(err, "EMAIL-s4is4", "could not set recipient: %v", recp)
return zerrors.ThrowInternalf(err, "EMAIL-s4is4", "could not set recipient: %v", recp)
}
}
@@ -87,7 +87,7 @@ func (email *Email) HandleMessage(message channels.Message) error {
func (smtpConfig SMTP) connectToSMTP(tlsRequired bool) (client *smtp.Client, err error) {
host, _, err := net.SplitHostPort(smtpConfig.Host)
if err != nil {
return nil, caos_errs.ThrowInternal(err, "EMAIL-spR56", "could not split host and port for connect to smtp")
return nil, zerrors.ThrowInternal(err, "EMAIL-spR56", "could not split host and port for connect to smtp")
}
if !tlsRequired {
@@ -109,7 +109,7 @@ func (smtpConfig SMTP) connectToSMTP(tlsRequired bool) (client *smtp.Client, err
func (smtpConfig SMTP) getSMPTClient() (*smtp.Client, error) {
client, err := smtp.Dial(smtpConfig.Host)
if err != nil {
return nil, caos_errs.ThrowInternal(err, "EMAIL-skwos", "could not make smtp dial")
return nil, zerrors.ThrowInternal(err, "EMAIL-skwos", "could not make smtp dial")
}
return client, nil
}
@@ -123,12 +123,12 @@ func (smtpConfig SMTP) getSMPTClientWithTls(host string) (*smtp.Client, error) {
}
if err != nil {
return nil, caos_errs.ThrowInternal(err, "EMAIL-sl39s", "could not make tls dial")
return nil, zerrors.ThrowInternal(err, "EMAIL-sl39s", "could not make tls dial")
}
client, err := smtp.NewClient(conn, host)
if err != nil {
return nil, caos_errs.ThrowInternal(err, "EMAIL-skwi4", "could not create smtp client")
return nil, zerrors.ThrowInternal(err, "EMAIL-skwi4", "could not create smtp client")
}
return client, err
}
@@ -142,7 +142,7 @@ func (smtpConfig SMTP) getSMPTClientWithStartTls(host string) (*smtp.Client, err
if err := client.StartTLS(&tls.Config{
ServerName: host,
}); err != nil {
return nil, caos_errs.ThrowInternal(err, "EMAIL-guvsQ", "could not start tls")
return nil, zerrors.ThrowInternal(err, "EMAIL-guvsQ", "could not start tls")
}
return client, nil
}
@@ -157,7 +157,7 @@ func (smtpConfig SMTP) smtpAuth(client *smtp.Client, host string) error {
}
err := client.Auth(auth)
if err != nil {
return caos_errs.ThrowInternalf(err, "EMAIL-s9kfs", "could not add smtp auth for user %s", smtpConfig.User)
return zerrors.ThrowInternalf(err, "EMAIL-s9kfs", "could not add smtp auth for user %s", smtpConfig.User)
}
return nil
}

View File

@@ -4,9 +4,9 @@ import (
"github.com/kevinburke/twilio-go"
"github.com/zitadel/logging"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/notification/channels"
"github.com/zitadel/zitadel/internal/notification/messages"
"github.com/zitadel/zitadel/internal/zerrors"
)
func InitChannel(config Config) channels.NotificationChannel {
@@ -17,7 +17,7 @@ func InitChannel(config Config) channels.NotificationChannel {
return channels.HandleMessageFunc(func(message channels.Message) error {
twilioMsg, ok := message.(*messages.SMS)
if !ok {
return caos_errs.ThrowInternal(nil, "TWILI-s0pLc", "message is not SMS")
return zerrors.ThrowInternal(nil, "TWILI-s0pLc", "message is not SMS")
}
content, err := twilioMsg.GetContent()
if err != nil {
@@ -25,7 +25,7 @@ func InitChannel(config Config) channels.NotificationChannel {
}
m, err := client.Messages.SendMessage(twilioMsg.SenderPhoneNumber, twilioMsg.RecipientPhoneNumber, content, nil)
if err != nil {
return caos_errs.ThrowInternal(err, "TWILI-osk3S", "could not send message")
return zerrors.ThrowInternal(err, "TWILI-osk3S", "could not send message")
}
logging.WithFields("message_sid", m.Sid, "status", m.Status).Debug("sms sent")
return nil

View File

@@ -9,9 +9,9 @@ import (
"github.com/zitadel/logging"
"github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/notification/channels"
"github.com/zitadel/zitadel/internal/notification/messages"
"github.com/zitadel/zitadel/internal/zerrors"
)
func InitChannel(ctx context.Context, cfg Config) (channels.NotificationChannel, error) {
@@ -25,7 +25,7 @@ func InitChannel(ctx context.Context, cfg Config) (channels.NotificationChannel,
defer cancel()
msg, ok := message.(*messages.JSON)
if !ok {
return errors.ThrowInternal(nil, "WEBH-K686U", "message is not JSON")
return zerrors.ThrowInternal(nil, "WEBH-K686U", "message is not JSON")
}
payload, err := msg.GetContent()
if err != nil {
@@ -47,7 +47,7 @@ func InitChannel(ctx context.Context, cfg Config) (channels.NotificationChannel,
return err
}
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
return errors.ThrowUnknown(fmt.Errorf("calling url %s returned %s", cfg.CallURL, resp.Status), "WEBH-LBxU0", "webhook didn't return a success status")
return zerrors.ThrowUnknown(fmt.Errorf("calling url %s returned %s", cfg.CallURL, resp.Status), "WEBH-LBxU0", "webhook didn't return a success status")
}
logging.WithFields("calling_url", cfg.CallURL, "method", cfg.Method).Debug("webhook called")
return nil