chenhg5/cc-connect · error

line: channel_secret and channel_token are required

Error message

line: channel_secret and channel_token are required

What it means

line.New validates that the options map contains non-empty channel_secret and channel_token values and fails fast with this error otherwise. The LINE Messaging API requires both to sign/verify webhooks and to authenticate API calls. New returns nil platform and this error when either credential is missing or empty.

Source

Thrown at platform/line/line.go:49

type Platform struct {
	channelSecret string
	channelToken  string
	allowFrom     string
	port          string
	callbackPath  string
	bot           *messaging_api.MessagingApiAPI
	server        *http.Server
	handler       core.MessageHandler
	userNameCache sync.Map // userID -> display name
	groupNameCache sync.Map // groupID -> group name
}

func New(opts map[string]any) (core.Platform, error) {
	secret, _ := opts["channel_secret"].(string)
	token, _ := opts["channel_token"].(string)
	allowFrom, _ := opts["allow_from"].(string)
	if secret == "" || token == "" {
		return nil, fmt.Errorf("line: channel_secret and channel_token are required")
	}

	port, _ := opts["port"].(string)
	if port == "" {
		port = "8080"
	}
	path, _ := opts["callback_path"].(string)
	if path == "" {
		path = "/callback"
	}

	core.CheckAllowFrom("line", allowFrom)
	return &Platform{
		channelSecret: secret,
		channelToken:  token,
		allowFrom:     allowFrom,
		port:          port,
		callbackPath:  path,

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Add valid channel_secret and channel_token string values from the LINE Developers Console to the options.
  2. Verify the option keys are exactly "channel_secret" and "channel_token".
  3. Check config.toml interpolation: ensure env vars like ${LINE_CHANNEL_TOKEN} are actually set in the shell/service environment.
  4. Ensure the values are strings, not numbers or other types.

Example fix

// before
line.New(map[string]any{"channel_token": token})
// after
line.New(map[string]any{"channel_secret": secret, "channel_token": token})
Defensive patterns

Strategy: validation

Validate before calling

// Go: validate options before calling line.New
func validLineOpts(opts map[string]any) error {
    secret, _ := opts["channel_secret"].(string)
    token, _ := opts["channel_token"].(string)
    if secret == "" || token == "" {
        return fmt.Errorf("line: channel_secret and channel_token must be non-empty strings (got secret=%q, token=%q)", secret, token)
    }
    return nil
}

Type guard

// Go: narrowing check
secret, secretOK := opts["channel_secret"].(string)
token, tokenOK := opts["channel_token"].(string)
if !secretOK || !tokenOK || secret == "" || token == "" {
    return errors.New("line: channel_secret and channel_token must be non-empty strings")
}

Prevention

When it happens

Trigger: Calling line.New(opts) with opts missing the channel_secret or channel_token keys, or with either value set to "" (empty string), or with values of a non-string type (type assertion yields "").

Common situations: config.toml [platforms.line] section missing the fields; environment variable substitution resolving to empty; typo'd key names (channelToken instead of channel_token); passing ints or other non-string types.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/8a296381a6cb0f35. Report an issue: GitHub.