Skip to content

Commit b8b8f54

Browse files
committed
Replace try-catch blocks with -ErrorAction SilentlyContinue
1 parent 31c07ee commit b8b8f54

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

sentry-cli/integration-test/action.psm1

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,19 @@ class InvokeSentryResult
4848
foreach ($envelope in $this.Envelopes())
4949
{
5050
$lines = @($envelope -split "\\n")
51-
try
51+
$header = $lines[0].Trim() | ConvertFrom-Json
52+
$eventId = $header | Select-Object -ExpandProperty event_id -ErrorAction SilentlyContinue
53+
if ($eventId -and $ids -notcontains $eventId)
5254
{
53-
$header = $lines[0].Trim() | ConvertFrom-Json
54-
if ($header.event_id -and $ids -notcontains $header.event_id)
55+
$body = $lines | Select-Object -Skip 1 | Where-Object {
56+
($_ | ConvertFrom-Json | Select-Object -ExpandProperty event_id -ErrorAction SilentlyContinue) -eq $eventId
57+
} | Select-Object -First 1
58+
if ($body)
5559
{
56-
$body = $lines | Select-Object -Skip 1 | Where-Object {
57-
try { ($_ | ConvertFrom-Json).event_id -eq $header.event_id }
58-
catch { $false }
59-
} | Select-Object -First 1
60-
if ($body)
61-
{
62-
$ids += $header.event_id
63-
$events += $body
64-
}
60+
$ids += $eventId
61+
$events += $body
6562
}
6663
}
67-
catch { }
6864
}
6965
return $events
7066
}

sentry-cli/integration-test/tests/action.Tests.ps1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ helloworld
102102
$result = Invoke-SentryServer {
103103
param([string]$url)
104104
Invoke-WebRequest -Uri "$url/api/0/envelope" -Method Post -Body @'
105+
{"dsn":"https://e12d836b15bb49d7bbf99e64295d995b:@sentry.io/42","sent_at":"2025-11-20T03:52:42.924Z"}
106+
{"type":"session","length":42}
107+
{"sid":"66356dadc138458a8d5cd9e258065175"}
108+
'@
109+
Invoke-WebRequest -Uri "$url/api/0/envelope" -Method Post -Body @'
105110
{"event_id":"9ec79c33ec9942ab8353589fcb2e04dc","dsn":"https://e12d836b15bb49d7bbf99e64295d995b:@sentry.io/42","sent_at":"2025-11-20T03:53:38.929Z"}
106111
{"type":"event","length":47,"content_type":"application/json"}
107112
{"event_id":"9ec79c33ec9942ab8353589fcb2e04dc"}
@@ -114,7 +119,7 @@ helloworld
114119
}
115120

116121
Should -ActualValue $result.HasErrors() -BeFalse
117-
$result.Envelopes().Length | Should -Be 2
122+
$result.Envelopes().Length | Should -Be 3
118123
$result.Events().Length | Should -Be 1
119124
$result.Events()[0].Length | Should -Be 47
120125
}

0 commit comments

Comments
 (0)