Skip to content

Commit 273f503

Browse files
committed
feat: add patching aborted and cleanup failed event tracking
1 parent fbdc997 commit 273f503

File tree

2 files changed

+92
-6
lines changed

2 files changed

+92
-6
lines changed

src/backend/metrics/types.ts

+25
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,29 @@ export interface PatchingFailed {
228228
sensitiveProperties?: never
229229
}
230230

231+
export interface PatchingAborted {
232+
event: 'Patching Aborted'
233+
properties: {
234+
game_name: string
235+
game_title: string
236+
platform: ReturnType<typeof getPlatformName>
237+
platform_arch: InstallPlatform
238+
}
239+
sensitiveProperties?: never
240+
}
241+
242+
export interface PatchingCleanupFailed {
243+
event: 'Patching Cleanup Failed'
244+
properties: {
245+
game_name: string
246+
error: string
247+
game_title: string
248+
platform?: ReturnType<typeof getPlatformName>
249+
platform_arch?: InstallPlatform
250+
}
251+
sensitiveProperties?: never
252+
}
253+
231254
export interface PatchingTooSlow {
232255
event: 'Patching Too Slow'
233256
properties: {
@@ -475,6 +498,8 @@ export type PossibleMetricPayloads =
475498
| PatchingStarted
476499
| PatchingSuccess
477500
| PatchingFailed
501+
| PatchingAborted
502+
| PatchingCleanupFailed
478503
| PatchingTooSlow
479504
| AccountDropdownPortfolioClicked
480505

src/backend/storeManagers/hyperplay/games.ts

+67-6
Original file line numberDiff line numberDiff line change
@@ -2011,8 +2011,35 @@ async function applyPatching(
20112011
}
20122012
// need this to cover 100% of abort cases
20132013
if (aborted) {
2014-
await safeRemoveDirectory(datastoreDir, {
2015-
sizeThresholdMB: blockSize * totalBlocks
2014+
try {
2015+
await safeRemoveDirectory(datastoreDir, {
2016+
sizeThresholdMB: blockSize * totalBlocks
2017+
})
2018+
} catch (cleanupError) {
2019+
trackEvent({
2020+
event: 'Patching Cleanup Failed',
2021+
properties: {
2022+
error: `${cleanupError}`,
2023+
game_name: gameInfo.app_name,
2024+
game_title: gameInfo.title,
2025+
platform: getPlatformName(platform),
2026+
platform_arch: platform
2027+
}
2028+
})
2029+
2030+
logWarning(
2031+
`Patching aborted and cleanup failed: ${cleanupError}`,
2032+
LogPrefix.HyperPlay
2033+
)
2034+
}
2035+
trackEvent({
2036+
event: 'Patching Aborted',
2037+
properties: {
2038+
game_name: gameInfo.app_name,
2039+
game_title: gameInfo.title,
2040+
platform: getPlatformName(platform),
2041+
platform_arch: platform
2042+
}
20162043
})
20172044
return { status: 'abort' }
20182045
}
@@ -2028,9 +2055,27 @@ async function applyPatching(
20282055
})
20292056

20302057
logInfo(`Patching ${appName} completed`, LogPrefix.HyperPlay)
2031-
await safeRemoveDirectory(datastoreDir, {
2032-
sizeThresholdMB: blockSize * totalBlocks
2033-
})
2058+
try {
2059+
await safeRemoveDirectory(datastoreDir, {
2060+
sizeThresholdMB: blockSize * totalBlocks
2061+
})
2062+
} catch (cleanupError) {
2063+
trackEvent({
2064+
event: 'Patching Cleanup Failed',
2065+
properties: {
2066+
error: `${cleanupError}`,
2067+
game_name: gameInfo.app_name,
2068+
game_title: gameInfo.title,
2069+
platform: getPlatformName(platform),
2070+
platform_arch: platform
2071+
}
2072+
})
2073+
2074+
logWarning(
2075+
`Patching succeeded but cleanup failed: ${cleanupError}`,
2076+
LogPrefix.HyperPlay
2077+
)
2078+
}
20342079
return { status: 'done' }
20352080
} catch (error) {
20362081
if (error instanceof PatchingError) {
@@ -2070,7 +2115,23 @@ async function applyPatching(
20702115

20712116
// errors can be thrown before datastore dir created. rmSync on nonexistent dir blocks indefinitely
20722117
if (existsSync(datastoreDir)) {
2073-
await safeRemoveDirectory(datastoreDir)
2118+
try {
2119+
await safeRemoveDirectory(datastoreDir)
2120+
} catch (cleanupError) {
2121+
trackEvent({
2122+
event: 'Patching Cleanup Failed',
2123+
properties: {
2124+
error: `${cleanupError}`,
2125+
game_name: gameInfo.app_name,
2126+
game_title: gameInfo.title
2127+
}
2128+
})
2129+
2130+
logWarning(
2131+
`Patching failed and cleanup failed: ${cleanupError}`,
2132+
LogPrefix.HyperPlay
2133+
)
2134+
}
20742135
}
20752136

20762137
return { status: 'error', error: `Error while patching ${error}` }

0 commit comments

Comments
 (0)