humanise: update error list and move generator

This commit is contained in:
Tulir Asokan
2025-12-03 14:34:42 +02:00
parent 55f8d1423b
commit 8e7a7db85f
4 changed files with 17 additions and 7 deletions
+9 -1
View File
@@ -74,6 +74,8 @@ func Error(err error) string {
return "The command description was empty, too long or had invalid characters used"
case tgerr.Is(err, "BOT_COMMAND_INVALID"):
return "The specified command is invalid"
case tgerr.Is(err, "BOT_COMMANDS_TOO_MUCH"):
return "The provided commands are too many"
case tgerr.Is(err, "BOT_DOMAIN_INVALID"):
return "The domain used for the auth button does not match the one configured in @BotFather"
case tgerr.Is(err, "BOT_GAMES_DISABLED"):
@@ -364,6 +366,8 @@ func Error(err error) string {
return "A wait of {seconds} seconds is required in the test servers"
case tgerr.Is(err, "FLOOD_WAIT_X"):
return "A wait of {seconds} seconds is required"
case tgerr.Is(err, "FLOOD_PREMIUM_WAIT_X"):
return "A wait of {seconds} seconds is required in non-premium accounts"
case tgerr.Is(err, "FOLDER_ID_EMPTY"):
return "The folder you tried to delete was already empty"
case tgerr.Is(err, "FOLDER_ID_INVALID"):
@@ -531,7 +535,7 @@ func Error(err error) string {
case tgerr.Is(err, "MESSAGE_POLL_CLOSED"):
return "The poll was closed and can no longer be voted on"
case tgerr.Is(err, "MESSAGE_TOO_LONG"):
return "Message was too long. Current maximum length is 4096 UTF-8 characters"
return "Message was too long"
case tgerr.Is(err, "METHOD_INVALID"):
return "The API method is invalid and cannot be used"
case tgerr.Is(err, "MIN_DATE_INVALID"):
@@ -1054,6 +1058,10 @@ func Error(err error) string {
return "Telegram workers are too busy to respond immediately"
case tgerr.Is(err, "YOU_BLOCKED_USER"):
return "You blocked this user"
case tgerr.Is(err, "FROZEN_METHOD_INVALID"):
return "You tried to use a method that is not available for frozen accounts"
case tgerr.Is(err, "FROZEN_PARTICIPANT_MISSING"):
return "Your account is frozen and can't access the chat"
}
return err.Error()
}
@@ -33,6 +33,7 @@ BOTS_TOO_MUCH,400,There are too many bots in this chat/channel
BOT_CHANNELS_NA,400,Bots can't edit admin privileges
BOT_COMMAND_DESCRIPTION_INVALID,400,"The command description was empty, too long or had invalid characters used"
BOT_COMMAND_INVALID,400,The specified command is invalid
BOT_COMMANDS_TOO_MUCH,400,"The provided commands are too many"
BOT_DOMAIN_INVALID,400,The domain used for the auth button does not match the one configured in @BotFather
BOT_GAMES_DISABLED,400,Bot games cannot be used in this type of chat
BOT_GROUPS_BLOCKED,400,This bot can't be added to groups
@@ -178,6 +179,7 @@ FILTER_TITLE_EMPTY,400,The title field of the filter is empty
FIRSTNAME_INVALID,400,The first name is invalid
FLOOD_TEST_PHONE_WAIT_X,420,A wait of {seconds} seconds is required in the test servers
FLOOD_WAIT_X,420,A wait of {seconds} seconds is required
FLOOD_PREMIUM_WAIT_X,420,A wait of {seconds} seconds is required in non-premium accounts
FOLDER_ID_EMPTY,400,The folder you tried to delete was already empty
FOLDER_ID_INVALID,400,The folder you tried to use was not valid
FRESH_CHANGE_ADMINS_FORBIDDEN,400 406,Recently logged-in users cannot add or change admins
@@ -261,7 +263,7 @@ MESSAGE_IDS_EMPTY,400,No message ids were provided
MESSAGE_ID_INVALID,400,The specified message ID is invalid or you can't do that operation on such message
MESSAGE_NOT_MODIFIED,400,Content of the message was not modified
MESSAGE_POLL_CLOSED,400,The poll was closed and can no longer be voted on
MESSAGE_TOO_LONG,400,Message was too long. Current maximum length is 4096 UTF-8 characters
MESSAGE_TOO_LONG,400,Message was too long
METHOD_INVALID,400,The API method is invalid and cannot be used
MIN_DATE_INVALID,400,The specified minimum date is invalid
MSGID_DECREASE_RETRY,500,The request should be retried with a lower message ID
@@ -523,3 +525,5 @@ WEBPUSH_KEY_INVALID,400,The specified web push elliptic curve Diffie-Hellman pub
WEBPUSH_TOKEN_INVALID,400,The specified web push token is invalid
WORKER_BUSY_TOO_LONG_RETRY,500,Telegram workers are too busy to respond immediately
YOU_BLOCKED_USER,400,You blocked this user
FROZEN_METHOD_INVALID,420,You tried to use a method that is not available for frozen accounts
FROZEN_PARTICIPANT_MISSING,400,Your account is frozen and can't access the chat
1 2FA_CONFIRM_WAIT_X 420 The account is 2FA protected so it will be deleted in a week. Otherwise it can be reset in {seconds}
33 BOT_CHANNELS_NA 400 Bots can't edit admin privileges
34 BOT_COMMAND_DESCRIPTION_INVALID 400 The command description was empty, too long or had invalid characters used
35 BOT_COMMAND_INVALID 400 The specified command is invalid
36 BOT_COMMANDS_TOO_MUCH 400 The provided commands are too many
37 BOT_DOMAIN_INVALID 400 The domain used for the auth button does not match the one configured in @BotFather
38 BOT_GAMES_DISABLED 400 Bot games cannot be used in this type of chat
39 BOT_GROUPS_BLOCKED 400 This bot can't be added to groups
179 FIRSTNAME_INVALID 400 The first name is invalid
180 FLOOD_TEST_PHONE_WAIT_X 420 A wait of {seconds} seconds is required in the test servers
181 FLOOD_WAIT_X 420 A wait of {seconds} seconds is required
182 FLOOD_PREMIUM_WAIT_X 420 A wait of {seconds} seconds is required in non-premium accounts
183 FOLDER_ID_EMPTY 400 The folder you tried to delete was already empty
184 FOLDER_ID_INVALID 400 The folder you tried to use was not valid
185 FRESH_CHANGE_ADMINS_FORBIDDEN 400 406 Recently logged-in users cannot add or change admins
263 MESSAGE_ID_INVALID 400 The specified message ID is invalid or you can't do that operation on such message
264 MESSAGE_NOT_MODIFIED 400 Content of the message was not modified
265 MESSAGE_POLL_CLOSED 400 The poll was closed and can no longer be voted on
266 MESSAGE_TOO_LONG 400 Message was too long. Current maximum length is 4096 UTF-8 characters Message was too long
267 METHOD_INVALID 400 The API method is invalid and cannot be used
268 MIN_DATE_INVALID 400 The specified minimum date is invalid
269 MSGID_DECREASE_RETRY 500 The request should be retried with a lower message ID
525 WEBPUSH_TOKEN_INVALID 400 The specified web push token is invalid
526 WORKER_BUSY_TOO_LONG_RETRY 500 Telegram workers are too busy to respond immediately
527 YOU_BLOCKED_USER 400 You blocked this user
528 FROZEN_METHOD_INVALID 420 You tried to use a method that is not available for frozen accounts
529 FROZEN_PARTICIPANT_MISSING 400 Your account is frozen and can't access the chat
@@ -28,9 +28,7 @@ import (
)
func main() {
currentDir := exerrors.Must(os.Getwd())
errorCSV := exerrors.Must(os.Open(currentDir + "/../../internal/gen/errors.csv"))
errorCSV := exerrors.Must(os.Open("gen/errors.csv"))
reader := csv.NewReader(errorCSV)
var data bytes.Buffer
data.WriteString("package humanise\n")
@@ -62,5 +60,5 @@ func main() {
data.WriteString("return err.Error()")
data.WriteString("}")
exerrors.PanicIfNotNil(os.WriteFile(currentDir+"/errors.go", data.Bytes(), os.ModePerm))
exerrors.PanicIfNotNil(os.WriteFile("errors.go", data.Bytes(), os.ModePerm))
}
+1 -1
View File
@@ -17,5 +17,5 @@
// Package humanise turns things into human-readable strings.
package humanise
//go:generate go run ../../internal/gen
//go:generate go run ./gen
//go:generate goimports -w errors.go