chenhg5/cc-connect · error

line: create api client: %w

Error message

line: create api client: %w

What it means

Platform.Start creates a LINE Messaging API client via messaging_api.NewMessagingApiAPI(channelToken) and wraps any failure in this error. The LINE SDK returns an error when it cannot construct the client, most commonly because the channel token is empty or malformed. Start aborts and returns without starting the webhook HTTP server.

Source

Thrown at platform/line/line.go:78

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

func (p *Platform) Name() string { return "line" }

func (p *Platform) Start(handler core.MessageHandler) error {
	p.handler = handler

	bot, err := messaging_api.NewMessagingApiAPI(p.channelToken)
	if err != nil {
		return fmt.Errorf("line: create api client: %w", err)
	}
	p.bot = bot

	mux := http.NewServeMux()
	mux.HandleFunc(p.callbackPath, p.webhookHandler)

	p.server = &http.Server{
		Addr:    ":" + p.port,
		Handler: mux,
	}

	go func() {
		slog.Info("line: webhook server listening", "port", p.port, "path", p.callbackPath)
		if err := p.server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
			slog.Error("line: server error", "error", err)
		}
	}()

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Verify channel_token in config is a valid long-lived channel access token from the LINE Developers Console.
  2. Trim whitespace/newlines from the token value.
  3. Issue a fresh token if the current one was revoked or expired.
  4. Check the line-bot-sdk-go version for changed constructor behavior; pin a known-good version.

Example fix

// before
p.channelToken = os.Getenv("LINE_TOKEN") // empty if unset
// after
token := strings.TrimSpace(os.Getenv("LINE_TOKEN"))
if token == "" {
    return fmt.Errorf("line: LINE_TOKEN is not set")
}
p.channelToken = token
Defensive patterns

Strategy: validation

Validate before calling

// Go: check token before Start
if strings.TrimSpace(cfg.Token) == "" {
    return errors.New("line: channel_token must be set before Start")
}
if !strings.HasPrefix(cfg.Token, "eyJ") { // LINE channel access tokens are JWT-like
    return errors.New("line: channel_token does not look like a LINE access token")
}

Try / catch

// Go: wrap Start failure with context
if err := platform.Start(handler); err != nil {
    if strings.Contains(err.Error(), "create api client") {
        return fmt.Errorf("line platform failed to start: bad or revoked channel token: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: Calling Start with p.channelToken empty or invalid so the SDK's client constructor fails (token validation/rejection at construction time).

Common situations: Placeholder token left in config; token copied with whitespace/newline; token revoked or from the wrong channel; SDK version change making token validation stricter.

Understand the failure class

Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.

Related errors


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