Skip to content

Commit e7871ce

Browse files
committed
fix: improve error handling and code formatting in container pool initialization
1 parent 0b82757 commit e7871ce

4 files changed

Lines changed: 13 additions & 12 deletions

File tree

src/Zemu.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,12 @@ export default class Zemu {
169169
await Zemu.containerPool.initialize(config || defaultConfig)
170170
Zemu.poolInitialized = true
171171
} catch (error) {
172-
console.warn('Container pool initialization failed, falling back to individual containers:', error)
172+
console.warn(
173+
`Container pool initialization failed: ${error instanceof Error ? error.message : error}. Falling back to individual containers.`
174+
)
173175
Zemu.poolEnabled = false
174176
Zemu.containerPool = null
177+
Zemu.poolInitialized = false
175178
}
176179
}
177180

@@ -925,9 +928,9 @@ export default class Zemu {
925928
const nav: INavElement = {
926929
type: touchDevice ? ActionKind.Touch : ActionKind.RightClick,
927930
button: touchDevice
928-
? (imageIndex === 1 && isBlindSigning
931+
? imageIndex === 1 && isBlindSigning
929932
? getTouchElement(this.startOptions.model, ButtonKind.RejectButton)
930-
: getTouchElement(this.startOptions.model, ButtonKind.SwipeContinueButton))
933+
: getTouchElement(this.startOptions.model, ButtonKind.SwipeContinueButton)
931934
: dummyButton, // For non-touch devices, use dummy button since action type determines behavior
932935
}
933936
await this.runAction(nav, filename, waitForScreenUpdate, true)
@@ -937,9 +940,7 @@ export default class Zemu {
937940
if (!runLastAction) return imageIndex // do not run last action if requested
938941

939942
// Approve can be performed with Tap or PressAndHold
940-
const approveButton = touchDevice
941-
? getTouchElement(this.startOptions.model, this.startOptions.approveAction)
942-
: dummyButton
943+
const approveButton = touchDevice ? getTouchElement(this.startOptions.model, this.startOptions.approveAction) : dummyButton
943944

944945
if (this.startOptions.approveAction === ButtonKind.DynamicTapButton) {
945946
const events = await this.getEvents()

src/actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
******************************************************************************* */
1616
import { getTouchElement } from './buttons'
17-
import { ActionKind, ButtonKind, type INavElement, type TModel, SwipeDirection, type IButton } from './types'
17+
import { ActionKind, ButtonKind, type IButton, type INavElement, SwipeDirection, type TModel } from './types'
1818

1919
const dummyButton: IButton = {
2020
x: 0,

src/containerPool.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,11 +315,11 @@ export class ContainerPool {
315315
private async cleanupStaleContainers(): Promise<void> {
316316
try {
317317
// List all containers that match our naming pattern
318-
const containers = await this.docker.listContainers({
318+
const containers = await this.docker.listContainers({
319319
all: true,
320-
filters: {
321-
name: [`${BASE_NAME}-pool-`, `${BASE_NAME}-`]
322-
}
320+
filters: {
321+
name: [`${BASE_NAME}-pool-`, `${BASE_NAME}-`],
322+
},
323323
})
324324

325325
if (containers.length === 0) {

tests/globalsetup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const catchExit = () => {
1818
process.exit(1)
1919
})
2020

21-
process.on('unhandledRejection', (reason, promise) => {
21+
process.on('unhandledRejection', (reason, _promise) => {
2222
console.error('Unhandled rejection, cleaning up containers:', reason)
2323
cleanup()
2424
process.exit(1)

0 commit comments

Comments
 (0)