Skip to content

Commit 87b1797

Browse files
committed
fix: handle errors on resource cleanup and improve error messages
1 parent dfa5be9 commit 87b1797

12 files changed

Lines changed: 35 additions & 31 deletions

File tree

calling/audiobridge.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,11 @@ func NewAudioBridge(config *AudioBridgeConfig) (*AudioBridge, error) {
132132
"webex-bridge",
133133
)
134134
if err != nil {
135-
pc.Close()
135+
_ = pc.Close()
136136
return nil, err
137137
}
138138
if _, err := pc.AddTrack(localTrack); err != nil {
139-
pc.Close()
139+
_ = pc.Close()
140140
return nil, err
141141
}
142142

calling/call.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ func (c *Call) HandleMobiusEvent(event *MobiusCallEvent) {
523523
c.connected = false
524524
c.mu.Unlock()
525525
if c.media != nil {
526-
c.media.Close()
526+
_ = c.media.Close()
527527
}
528528
c.Emitter.Emit(string(CallEventDisconnect), c.callID)
529529

calling/callcontrol_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func TestMediaEngine(t *testing.T) {
9191
if me == nil {
9292
t.Fatal("Expected non-nil MediaEngine")
9393
}
94-
defer me.Close()
94+
defer func() { _ = me.Close() }()
9595
})
9696

9797
t.Run("NewMediaEngine with custom config", func(t *testing.T) {
@@ -103,7 +103,7 @@ func TestMediaEngine(t *testing.T) {
103103
if err != nil {
104104
t.Fatalf("Unexpected error: %v", err)
105105
}
106-
defer me.Close()
106+
defer func() { _ = me.Close() }()
107107
if me == nil {
108108
t.Fatal("Expected non-nil MediaEngine")
109109
}

calling/callingclient.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ func (cc *CallingClient) ConnectMercury(merc *mercury.Client) error {
746746

747747
log.Println("CallingClient: connecting Mercury WebSocket...")
748748
if err := merc.Connect(); err != nil {
749-
return fmt.Errorf("Mercury connection failed: %w", err)
749+
return fmt.Errorf("mercury connection failed: %w", err)
750750
}
751751
log.Println("CallingClient: Mercury WebSocket connected")
752752

encryption/encryption_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -615,8 +615,8 @@ func TestParseRSAPublicKeyFromJWK(t *testing.T) {
615615

616616
jwk := JWK{
617617
Kty: "RSA",
618-
N: base64.RawURLEncoding.EncodeToString(rsaKey.PublicKey.N.Bytes()),
619-
E: base64.RawURLEncoding.EncodeToString(big.NewInt(int64(rsaKey.PublicKey.E)).Bytes()),
618+
N: base64.RawURLEncoding.EncodeToString(rsaKey.N.Bytes()),
619+
E: base64.RawURLEncoding.EncodeToString(big.NewInt(int64(rsaKey.E)).Bytes()),
620620
Kid: "test-rsa-kid",
621621
}
622622

@@ -630,10 +630,10 @@ func TestParseRSAPublicKeyFromJWK(t *testing.T) {
630630
if kid != "test-rsa-kid" {
631631
t.Errorf("kid = %q, want %q", kid, "test-rsa-kid")
632632
}
633-
if pub.N.Cmp(rsaKey.PublicKey.N) != 0 {
633+
if pub.N.Cmp(rsaKey.N) != 0 {
634634
t.Error("RSA modulus does not match")
635635
}
636-
if pub.E != rsaKey.PublicKey.E {
636+
if pub.E != rsaKey.E {
637637
t.Errorf("RSA exponent = %d, want %d", pub.E, rsaKey.PublicKey.E)
638638
}
639639
}

examples/events/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,13 @@ func main() {
7575

7676
// Print data fields based on resource type
7777
fmt.Printf(" Data:\n")
78-
if eventDetails.Resource == "messages" {
78+
switch eventDetails.Resource {
79+
case "messages":
7980
fmt.Printf(" Room ID: %s\n", eventDetails.Data.RoomID)
8081
fmt.Printf(" Room Type: %s\n", eventDetails.Data.RoomType)
8182
fmt.Printf(" Person ID: %s\n", eventDetails.Data.PersonID)
8283
fmt.Printf(" Person Email: %s\n", eventDetails.Data.PersonEmail)
83-
} else if eventDetails.Resource == "meetings" {
84+
case "meetings":
8485
fmt.Printf(" Meeting ID: %s\n", eventDetails.Data.MeetingID)
8586
fmt.Printf(" Creator ID: %s\n", eventDetails.Data.CreatorID)
8687
fmt.Printf(" Recording Enabled: %s\n", eventDetails.Data.RecordingEnabled)

examples/messages-listen/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func main() {
7070

7171
// Clean up
7272
fmt.Println("Stopping message listener...")
73-
messagesClient.StopListening()
73+
_ = messagesClient.StopListening()
7474

7575
fmt.Println("Exiting.")
7676
}

mercury/mercury.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ func (c *Client) attemptConnection(wsURL string) error {
363363

364364
// Authenticate the connection
365365
if err = c.authenticateConnection(conn, token); err != nil {
366-
conn.Close()
366+
_ = conn.Close()
367367
return err
368368
}
369369

@@ -795,7 +795,7 @@ func (c *Client) reconnect() {
795795

796796
// Close the old connection if it exists
797797
if conn != nil {
798-
conn.Close()
798+
_ = conn.Close()
799799
}
800800

801801
// Try to reconnect

messages/messages_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ func TestCreateWithAttachment_RawBytes(t *testing.T) {
397397
if err != nil {
398398
t.Fatalf("Failed to get uploaded file: %v", err)
399399
}
400-
defer file.Close()
400+
defer func() { _ = file.Close() }()
401401

402402
if header.Filename != "test.txt" {
403403
t.Errorf("Expected filename 'test.txt', got '%s'", header.Filename)
@@ -452,7 +452,7 @@ func TestCreateWithBase64File(t *testing.T) {
452452
if err != nil {
453453
t.Fatalf("Failed to get uploaded file: %v", err)
454454
}
455-
defer file.Close()
455+
defer func() { _ = file.Close() }()
456456

457457
if header.Filename != "report.pdf" {
458458
t.Errorf("Expected filename 'report.pdf', got '%s'", header.Filename)

recordings/recordings_test.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,8 @@ func TestDownloadAudio(t *testing.T) {
332332

333333
// Use a single server for both API and download
334334
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
335-
if r.URL.Path == "/recordings/rec-123" {
335+
switch r.URL.Path {
336+
case "/recordings/rec-123":
336337
w.Header().Set("Content-Type", "application/json")
337338
recording := Recording{
338339
ID: "rec-123",
@@ -341,15 +342,15 @@ func TestDownloadAudio(t *testing.T) {
341342
},
342343
}
343344
_ = json.NewEncoder(w).Encode(recording)
344-
} else if r.URL.Path == "/download/audio.mp3" {
345+
case "/download/audio.mp3":
345346
if r.Header.Get("Authorization") != "Bearer test-token" {
346347
t.Errorf("Expected auth header on download request")
347348
}
348349
w.Header().Set("Content-Type", "audio/mpeg")
349350
w.Header().Set("Content-Disposition", `attachment; filename="audio.mp3"`)
350351
w.WriteHeader(http.StatusOK)
351352
_, _ = w.Write(audioContent)
352-
} else {
353+
default:
353354
t.Errorf("Unexpected path: %s", r.URL.Path)
354355
w.WriteHeader(http.StatusNotFound)
355356
}
@@ -384,7 +385,8 @@ func TestDownloadRecording(t *testing.T) {
384385
videoContent := []byte("fake mp4 video content")
385386

386387
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
387-
if r.URL.Path == "/recordings/rec-123" {
388+
switch r.URL.Path {
389+
case "/recordings/rec-123":
388390
w.Header().Set("Content-Type", "application/json")
389391
recording := Recording{
390392
ID: "rec-123",
@@ -393,11 +395,11 @@ func TestDownloadRecording(t *testing.T) {
393395
},
394396
}
395397
_ = json.NewEncoder(w).Encode(recording)
396-
} else if r.URL.Path == "/download/video.mp4" {
398+
case "/download/video.mp4":
397399
w.Header().Set("Content-Type", "video/mp4")
398400
w.WriteHeader(http.StatusOK)
399401
_, _ = w.Write(videoContent)
400-
} else {
402+
default:
401403
w.WriteHeader(http.StatusNotFound)
402404
}
403405
}))
@@ -431,7 +433,8 @@ func TestDownloadTranscript(t *testing.T) {
431433
transcriptContent := []byte("Speaker 1: Hello\nSpeaker 2: Hi there")
432434

433435
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
434-
if r.URL.Path == "/recordings/rec-123" {
436+
switch r.URL.Path {
437+
case "/recordings/rec-123":
435438
w.Header().Set("Content-Type", "application/json")
436439
recording := Recording{
437440
ID: "rec-123",
@@ -440,13 +443,13 @@ func TestDownloadTranscript(t *testing.T) {
440443
},
441444
}
442445
_ = json.NewEncoder(w).Encode(recording)
443-
} else if r.URL.Path == "/download/transcript.txt" {
446+
case "/download/transcript.txt":
444447
w.Header().Set("Content-Type", "text/plain")
445448
w.WriteHeader(http.StatusOK)
446449
if _, err := w.Write(transcriptContent); err != nil {
447450
t.Logf("Failed to write response: %v", err)
448451
}
449-
} else {
452+
default:
450453
w.WriteHeader(http.StatusNotFound)
451454
}
452455
}))

0 commit comments

Comments
 (0)