chenhg5/cc-connect · error
line: invalid session key %q
Error message
line: invalid session key %q
What it means
ReconstructReplyCtx parses a session key of the form "line:{targetID}". If the key has no colon-separated prefix or the prefix is not "line", it returns "line: invalid session key %q". The library throws it to reject session keys that were not produced by this platform's session-key format.
Source
Thrown at platform/line/line.go:312
}
var parts []string
runes := []rune(s)
for len(runes) > 0 {
end := maxLen
if end > len(runes) {
end = len(runes)
}
parts = append(parts, string(runes[:end]))
runes = runes[end:]
}
return parts
}
func (p *Platform) ReconstructReplyCtx(sessionKey string) (any, error) {
// line:{targetID} (user or group)
parts := strings.SplitN(sessionKey, ":", 2)
if len(parts) < 2 || parts[0] != "line" {
return nil, fmt.Errorf("line: invalid session key %q", sessionKey)
}
return replyContext{targetID: parts[1], targetType: "user"}, nil
}
func (p *Platform) Stop() error {
if p.server != nil {
return p.server.Shutdown(context.Background())
}
return nil
}
View on GitHub (pinned to 4000b2338a)
Solutions
- Ensure the session key passed in is in the "line:{targetID}" format
- Verify you are calling line.Platform's ReconstructReplyCtx, not another platform's, for LINE keys
- Log the offending sessionKey (%q) and fix whatever persisted/generated it
Example fix
// before
ctx, err := p.ReconstructReplyCtx("U1234abcd")
// after
key := "line:U1234abcd"
if !strings.HasPrefix(key, "line:") {
key = "line:" + key
}
ctx, err := p.ReconstructReplyCtx(key) Defensive patterns
Strategy: validation
Validate before calling
func validLineSessionKey(key string) bool {
parts := strings.SplitN(key, ":", 2)
return len(parts) == 2 && parts[0] == "line" && parts[1] != ""
} Type guard
null
Try / catch
if err != nil {
if strings.Contains(err.Error(), "invalid session key") {
slog.Warn("skipping non-LINE session key", "key", key)
return
}
return err
} Prevention
- Always persist session keys in the "line:{targetID}" form
- Never hand-strip or edit stored session keys
- Match the platform adapter to the key prefix before reconstructing
- Include the prefix when generating keys from raw channel IDs
When it happens
Trigger: Calling ReconstructReplyCtx with a sessionKey that lacks the "line:" prefix (e.g. "123456"), contains no ':' at all, or belongs to another platform (e.g. "telegram:123").
Common situations: Passing a raw chat/user ID instead of the prefixed session key; storing/reconstructing a session across platform adapters; corrupted or manually edited persisted session records.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- dingtalk: invalid session key format: %q
- empty batch spec
- empty batch item
- invalid range %q
- invalid source session key: %w
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/17be8e2e0f2d3662.
Report an issue: GitHub.