From 0902a7ac55e7d379e7c36c768ffb56bf88b2fff5 Mon Sep 17 00:00:00 2001 From: Robin Neatherway Date: Tue, 26 Apr 2022 15:00:57 +0100 Subject: [PATCH] Improve error message --- internal/slackclient/token.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/internal/slackclient/token.go b/internal/slackclient/token.go index fb0f887..50923f7 100644 --- a/internal/slackclient/token.go +++ b/internal/slackclient/token.go @@ -91,20 +91,22 @@ func getSlackAuth(team string) (*SlackAuth, error) { return &SlackAuth{Token: string(matches[1]), Cookies: map[string]string{"d": cookie}}, nil } +var errorNoSlackAuth = errors.New("environment variable SLACK_AUTH not in expected format. Try cloning https://github.com/chrisgavin/slacktoken and running `export SLACK_TOKEN=\"$(python3 -m slacktoken get --workspace github\")`") + func getSlackAuthFromEnv() (*SlackAuth, error) { slackAuth := os.Getenv("SLACK_AUTH") if slackAuth == "" { - return nil, errors.New("environment variable SLACK_AUTH not set") + return nil, errorNoSlackAuth } token, cookie, found := strings.Cut(slackAuth, "\n") if !found { - return nil, errors.New("environment variable SLACK_AUTH not in expected format") + return nil, errorNoSlackAuth } key, value, found := strings.Cut(cookie, "=") if !found { - return nil, errors.New("environment variable SLACK_AUTH not in expected format") + return nil, errorNoSlackAuth } cookie, err := url.PathUnescape(value)