Skip to content

Commit

Permalink
Improve error message
Browse files Browse the repository at this point in the history
  • Loading branch information
rneatherway committed Apr 26, 2022
1 parent 31514f2 commit 0902a7a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions internal/slackclient/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0902a7a

Please sign in to comment.