From 39b2717ea88797677d76e71eb53958aae69038bc Mon Sep 17 00:00:00 2001 From: Somtochi Onyekwere Date: Thu, 19 May 2022 12:37:20 +0100 Subject: [PATCH] Better error messages for providers Signed-off-by: Somtochi Onyekwere --- internal/notifier/alertmanager.go | 2 +- internal/notifier/discord.go | 2 +- internal/notifier/matrix.go | 2 +- internal/notifier/opsgenie.go | 2 +- internal/notifier/rocket.go | 2 +- internal/notifier/slack.go | 2 +- internal/notifier/teams.go | 2 +- internal/notifier/webex.go | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/internal/notifier/alertmanager.go b/internal/notifier/alertmanager.go index efee975ff..8bef655d6 100644 --- a/internal/notifier/alertmanager.go +++ b/internal/notifier/alertmanager.go @@ -40,7 +40,7 @@ type AlertManagerAlert struct { func NewAlertmanager(hookURL string, proxyURL string, certPool *x509.CertPool) (*Alertmanager, error) { _, err := url.ParseRequestURI(hookURL) if err != nil { - return nil, fmt.Errorf("invalid Alertmanager URL %s", hookURL) + return nil, fmt.Errorf("invalid Alertmanager URL %s: '%w'", hookURL, err) } return &Alertmanager{ diff --git a/internal/notifier/discord.go b/internal/notifier/discord.go index 1e0bd9f05..d19c86511 100644 --- a/internal/notifier/discord.go +++ b/internal/notifier/discord.go @@ -37,7 +37,7 @@ type Discord struct { func NewDiscord(hookURL string, proxyURL string, username string, channel string) (*Discord, error) { webhook, err := url.ParseRequestURI(hookURL) if err != nil { - return nil, fmt.Errorf("invalid Discord hook URL %s", hookURL) + return nil, fmt.Errorf("invalid Discord hook URL %s: '%w'", hookURL, err) } // use Slack formatting diff --git a/internal/notifier/matrix.go b/internal/notifier/matrix.go index d68ad7079..84db5e8bb 100644 --- a/internal/notifier/matrix.go +++ b/internal/notifier/matrix.go @@ -28,7 +28,7 @@ type MatrixPayload struct { func NewMatrix(serverURL, token, roomId string, certPool *x509.CertPool) (*Matrix, error) { _, err := url.ParseRequestURI(serverURL) if err != nil { - return nil, fmt.Errorf("invalid Matrix homeserver URL %s", serverURL) + return nil, fmt.Errorf("invalid Matrix homeserver URL %s: '%w'", serverURL, err) } return &Matrix{ diff --git a/internal/notifier/opsgenie.go b/internal/notifier/opsgenie.go index 8e2a711d0..46f293ef4 100644 --- a/internal/notifier/opsgenie.go +++ b/internal/notifier/opsgenie.go @@ -42,7 +42,7 @@ type OpsgenieAlert struct { func NewOpsgenie(hookURL string, proxyURL string, certPool *x509.CertPool, token string) (*Opsgenie, error) { _, err := url.ParseRequestURI(hookURL) if err != nil { - return nil, fmt.Errorf("invalid Opsgenie hook URL %s", hookURL) + return nil, fmt.Errorf("invalid Opsgenie hook URL %s: '%w'", hookURL, err) } if token == "" { diff --git a/internal/notifier/rocket.go b/internal/notifier/rocket.go index e6542a548..5de28e756 100644 --- a/internal/notifier/rocket.go +++ b/internal/notifier/rocket.go @@ -39,7 +39,7 @@ type Rocket struct { func NewRocket(hookURL string, proxyURL string, certPool *x509.CertPool, username string, channel string) (*Rocket, error) { _, err := url.ParseRequestURI(hookURL) if err != nil { - return nil, fmt.Errorf("invalid Rocket hook URL %s", hookURL) + return nil, fmt.Errorf("invalid Rocket hook URL %s: '%w'", hookURL, err) } if username == "" { diff --git a/internal/notifier/slack.go b/internal/notifier/slack.go index 2477dd1f1..23e7d814b 100644 --- a/internal/notifier/slack.go +++ b/internal/notifier/slack.go @@ -65,7 +65,7 @@ type SlackField struct { func NewSlack(hookURL string, proxyURL string, token string, certPool *x509.CertPool, username string, channel string) (*Slack, error) { _, err := url.ParseRequestURI(hookURL) if err != nil { - return nil, fmt.Errorf("invalid Slack hook URL %s", hookURL) + return nil, fmt.Errorf("invalid Slack hook URL %s: '%w'", hookURL, err) } return &Slack{ diff --git a/internal/notifier/teams.go b/internal/notifier/teams.go index c558f3cd0..4c4a0c28e 100644 --- a/internal/notifier/teams.go +++ b/internal/notifier/teams.go @@ -57,7 +57,7 @@ type MSTeamsField struct { func NewMSTeams(hookURL string, proxyURL string, certPool *x509.CertPool) (*MSTeams, error) { _, err := url.ParseRequestURI(hookURL) if err != nil { - return nil, fmt.Errorf("invalid MS Teams webhook URL %s", hookURL) + return nil, fmt.Errorf("invalid MS Teams webhook URL %s: '%w'", hookURL, err) } return &MSTeams{ diff --git a/internal/notifier/webex.go b/internal/notifier/webex.go index 03d96ec9a..f80f48b5e 100644 --- a/internal/notifier/webex.go +++ b/internal/notifier/webex.go @@ -66,7 +66,7 @@ func NewWebex(hookURL, proxyURL string, certPool *x509.CertPool, channel string, _, err := url.ParseRequestURI(hookURL) if err != nil { - return nil, fmt.Errorf("invalid Webex hook URL %s", hookURL) + return nil, fmt.Errorf("invalid Webex hook URL %s: '%w'", hookURL, err) } return &Webex{