From 646eaeac23a67fcbb0d239c7824595e5d5745f52 Mon Sep 17 00:00:00 2001 From: Dan Anglin Date: Wed, 14 Aug 2024 03:03:02 +0100 Subject: [PATCH] checkpoint: more static error types --- internal/executor/add.go | 7 +++---- internal/executor/errors.go | 18 ++++++++++++++++++ internal/executor/flags.go | 2 -- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/internal/executor/add.go b/internal/executor/add.go index f32cdc7..a66bda1 100644 --- a/internal/executor/add.go +++ b/internal/executor/add.go @@ -1,7 +1,6 @@ package executor import ( - "errors" "fmt" "codeflow.dananglin.me.uk/apollo/enbas/internal/client" @@ -199,7 +198,7 @@ func (a *AddExecutor) addBoostToStatus(gtsClient *client.Client) error { func (a *AddExecutor) addVoteToStatus(gtsClient *client.Client) error { if a.votes.Empty() { - return errors.New("please use --" + flagVote + " to make a choice in this poll") + return NoVotesError{} } status, err := gtsClient.GetStatus(a.statusID) @@ -208,7 +207,7 @@ func (a *AddExecutor) addVoteToStatus(gtsClient *client.Client) error { } if status.Poll == nil { - return errors.New("this status does not have a poll") + return NoPollInStatusError{} } if status.Poll.Expired { @@ -225,7 +224,7 @@ func (a *AddExecutor) addVoteToStatus(gtsClient *client.Client) error { } if status.Account.ID == myAccountID { - return errors.New("you cannot vote in your own poll") + return PollOwnerVoteError{} } pollID := status.Poll.ID diff --git a/internal/executor/errors.go b/internal/executor/errors.go index f32927c..62e49c3 100644 --- a/internal/executor/errors.go +++ b/internal/executor/errors.go @@ -104,6 +104,24 @@ func (e NoPollOptionError) Error() string { " flag to add options to the poll" } +type NoVotesError struct{} + +func (e NoVotesError) Error() string { + return "no votes were made, please add your vote(s) using the --vote flag" +} + +type NoPollInStatusError struct{} + +func (e NoPollInStatusError) Error() string { + return "this status does not have a poll" +} + +type PollOwnerVoteError struct{} + +func (e PollOwnerVoteError) Error() string { + return "you cannot vote in your own poll" +} + type NotFollowingError struct { Account string } diff --git a/internal/executor/flags.go b/internal/executor/flags.go index 37eb7a0..992ccb5 100644 --- a/internal/executor/flags.go +++ b/internal/executor/flags.go @@ -8,11 +8,9 @@ const ( flagInstance = "instance" flagListID = "list-id" flagListTitle = "list-title" - flagPollID = "poll-id" flagPollOption = "poll-option" flagStatusID = "status-id" flagTag = "tag" flagTo = "to" flagType = "type" - flagVote = "vote" )