Skip to content

Commit 902217c

Browse files
committed
fix: indent comments
1 parent f35b6c1 commit 902217c

5 files changed

Lines changed: 363 additions & 43 deletions

File tree

pkg/connector/client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ type LineClient struct {
8080
knownMemberChatMIDs map[string]struct{} // chatMid -> current member chats returned by getAllChatMids
8181
reactionIconMXC map[int]string // predefinedReactionType -> cached MXC URI
8282
recentReactions sync.Map // "msgID\x00emoji" -> struct{} to dedup concurrent 139/140 events
83+
unblockBackfills sync.Map // chat MID -> *unblockBackfillState while unblock history restoration is active
8384

8485
wg sync.WaitGroup
8586
}

pkg/connector/connector.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package connector
33
import (
44
"context"
55
"encoding/json"
6+
"errors"
67
"fmt"
78
"net/http"
89
"strings"
@@ -368,15 +369,20 @@ func parseLoginErrorDetails(err error) loginErrorDetails {
368369
return details
369370
}
370371

371-
func loginErrorSummary(err error) string {
372+
func loginErrorSummary(err error, details loginErrorDetails) string {
372373
if err == nil {
373374
return ""
374375
}
375-
summary := strings.TrimSpace(err.Error())
376-
if jsonStart := strings.Index(summary, "{"); jsonStart >= 0 {
377-
summary = strings.TrimSpace(summary[:jsonStart])
376+
if details.HasHTTPStatus {
377+
return fmt.Sprintf("API error %d", details.HTTPStatus)
378+
}
379+
if errors.Is(err, context.DeadlineExceeded) {
380+
return "request timed out"
381+
}
382+
if errors.Is(err, context.Canceled) {
383+
return "request canceled"
378384
}
379-
return loginLogField(summary)
385+
return ""
380386
}
381387

382388
func loginLogField(value string) string {
@@ -398,7 +404,7 @@ func (ll *LineEmailLogin) logLoginFailure(err error, flow string) {
398404
event := ll.User.Log.Warn().
399405
Str("login_flow", flow).
400406
Bool("has_certificate", ll.Certificate != "")
401-
if summary := loginErrorSummary(err); summary != "" {
407+
if summary := loginErrorSummary(err, details); summary != "" {
402408
event.Str("error_summary", summary)
403409
}
404410
if details.HasHTTPStatus {

pkg/connector/login_error_logging_test.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"encoding/json"
77
"errors"
8+
"fmt"
89
"strings"
910
"testing"
1011

@@ -53,6 +54,7 @@ func TestSubmitUserInputLogsStructuredLoginErrorWithoutCredentials(t *testing.T)
5354
"message": "LINE login attempt failed",
5455
"login_flow": "credentials",
5556
"has_certificate": false,
57+
"error_summary": "API error 400",
5658
"http_status": float64(400),
5759
"line_response_code": float64(10051),
5860
"line_response_message": "RESPONSE_ERROR",
@@ -76,11 +78,28 @@ func TestSubmitUserInputLogsStructuredLoginErrorWithoutCredentials(t *testing.T)
7678
}
7779

7880
func TestParseLoginErrorDetailsWithoutJSON(t *testing.T) {
79-
details := parseLoginErrorDetails(errors.New("login failed: request failed: context deadline exceeded"))
81+
err := errors.New("login failed: request failed: context deadline exceeded")
82+
details := parseLoginErrorDetails(err)
8083
if details.HasHTTPStatus || details.HasResponseFields {
8184
t.Fatalf("unexpected parsed response details: %#v", details)
8285
}
83-
if got := loginErrorSummary(errors.New("login failed: request failed: context deadline exceeded")); got != "login failed: request failed: context deadline exceeded" {
84-
t.Fatalf("loginErrorSummary = %q", got)
86+
if got := loginErrorSummary(err, details); got != "" {
87+
t.Fatalf("loginErrorSummary = %q, want empty", got)
88+
}
89+
}
90+
91+
func TestLoginErrorSummaryDoesNotIncludeNonJSONResponseBody(t *testing.T) {
92+
err := errors.New("login failed: API error 502: upstream secret response")
93+
details := parseLoginErrorDetails(err)
94+
if got := loginErrorSummary(err, details); got != "API error 502" {
95+
t.Fatalf("loginErrorSummary = %q, want %q", got, "API error 502")
96+
}
97+
}
98+
99+
func TestLoginErrorSummaryAllowsKnownContextErrors(t *testing.T) {
100+
err := fmt.Errorf("login failed: %w", context.DeadlineExceeded)
101+
details := parseLoginErrorDetails(err)
102+
if got := loginErrorSummary(err, details); got != "request timed out" {
103+
t.Fatalf("loginErrorSummary = %q, want %q", got, "request timed out")
85104
}
86105
}

0 commit comments

Comments
 (0)