chenhg5/cc-connect · error

line: push message

Error message

line: push message: %w

What it means

In Reply, platform/line/line.go:280, the LINE client's PushMessage API call failed and the error is wrapped as "line: push message: %w". The library throws it whenever sending a proactive/push message to the LINE Messaging API returns a non-nil error (network failure, invalid token, or invalid targetID). It propagates the underlying LINE API error so callers can see the root cause.

Solutions

  1. Check the wrapped inner error (via errors.Unwrap or %v of the error) for the LINE API status code and message
  2. Verify the channel access token is valid and not expired; refresh/rotate it
  3. Confirm the bot is a friend of / member of the target user or group before pushing
  4. Retry on transient network/5xx errors with backoff; respect LINE rate limits

Example fix

// before
if err != nil {
    return fmt.Errorf("line: push message: %w", err)
}
// after
if err != nil {
    var apiErr *linebot.APIError
    if errors.As(err, &apiErr) && apiErr.Code == 429 {
        return retryAfterBackoff(...)
    }
    return fmt.Errorf("line: push message: %w", err)
}
Defensive patterns

Strategy: try-catch

Validate before calling

if !strings.HasPrefix(sessionKey, "line:") { return fmt.Errorf("not a LINE session key") }

Type guard

func isLinebotAPIError(err error) (*linebot.APIError, bool) { var e *linebot.APIError; ok := errors.As(err, &e); return e, ok }

Try / catch

if err != nil {
    var apiErr *linebot.APIError
    if errors.As(err, &apiErr) {
        slog.Warn("line push failed", "code", apiErr.Code, "msg", apiErr.Message)
        if apiErr.Code == 429 { /* backoff + retry */ }
        return
    }
    slog.Error("line push failed", "err", err)
}

Prevention

When it happens

Trigger: Calling Reply when the underlying linebot client PushMessage call (to the target user/group/channel text) returns an error — e.g. HTTP error from LINE servers, network outage, expired/invalid channel access token, or the bot has no relationship with the target ID.

Common situations: Bot tries to push a message to a user who has not added it as a friend (LINE requires no push to non-friends); channel token revoked or expired; LINE platform outage or rate limit; misconfigured target ID in session key.

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/3bf68aa429d86eb0. Report an issue: GitHub.

Appendix: source

Thrown at platform/line/line.go:280

	}

	content = core.StripMarkdown(content)

	// LINE text message limit is 5000 characters
	messages := splitMessage(content, 5000)
	for _, text := range messages {
		_, err := p.bot.PushMessage(
			&messaging_api.PushMessageRequest{
				To: rc.targetID,
				Messages: []messaging_api.MessageInterface{
					messaging_api.TextMessage{
						Text: text,
					},
				},
			}, "",
		)
		if err != nil {
			return fmt.Errorf("line: push message: %w", err)
		}
	}
	return nil
}

// Send sends a new message (same as Reply for LINE)
func (p *Platform) Send(ctx context.Context, rctx any, content string) error {
	return p.Reply(ctx, rctx, content)
}

func splitMessage(s string, maxLen int) []string {
	if len(s) <= maxLen {
		return []string{s}
	}
	var parts []string
	runes := []rune(s)
	for len(runes) > 0 {
		end := maxLen

View on GitHub (pinned to 4000b2338a)