refactor(core): suppress mask/highlight errors instead of failing the run
Visual feedback failures (showMask, hideMask, cleanUpHighlights) are non-critical; log them instead of aborting the task or masking the original error during teardown.
This commit is contained in:
@@ -21,7 +21,7 @@ import type {
|
|||||||
MacroToolInput,
|
MacroToolInput,
|
||||||
MacroToolResult,
|
MacroToolResult,
|
||||||
} from './types'
|
} from './types'
|
||||||
import { assert, fetchLlmsTxt, normalizeResponse, uid, waitFor } from './utils'
|
import { assert, fetchLlmsTxt, normalizeResponse, suppress, uid, waitFor } from './utils'
|
||||||
|
|
||||||
export { tool, type PageAgentTool } from './tools'
|
export { tool, type PageAgentTool } from './tools'
|
||||||
export type * from './types'
|
export type * from './types'
|
||||||
@@ -244,10 +244,10 @@ export class PageAgentCore extends EventTarget {
|
|||||||
let taskResult: ExecutionResult
|
let taskResult: ExecutionResult
|
||||||
let finalStatus: AgentStatus = 'error'
|
let finalStatus: AgentStatus = 'error'
|
||||||
|
|
||||||
|
await suppress(() => this.pageController.showMask())
|
||||||
|
|
||||||
// graceful exit
|
// graceful exit
|
||||||
try {
|
try {
|
||||||
await this.pageController.showMask()
|
|
||||||
|
|
||||||
await onBeforeTask?.(this)
|
await onBeforeTask?.(this)
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
@@ -368,8 +368,8 @@ export class PageAgentCore extends EventTarget {
|
|||||||
finalStatus = 'error'
|
finalStatus = 'error'
|
||||||
throw error
|
throw error
|
||||||
} finally {
|
} finally {
|
||||||
this.pageController.cleanUpHighlights()
|
suppress(() => this.pageController.cleanUpHighlights())
|
||||||
this.pageController.hideMask()
|
suppress(() => this.pageController.hideMask())
|
||||||
this.#abortController.abort()
|
this.#abortController.abort()
|
||||||
settleRun(finalStatus)
|
settleRun(finalStatus)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -129,3 +129,15 @@ export function assert(condition: unknown, message?: string, silent?: boolean):
|
|||||||
throw new Error(errorMessage)
|
throw new Error(errorMessage)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Suppress errors from a function.
|
||||||
|
*/
|
||||||
|
export function suppress<T>(fn: () => T): T | undefined {
|
||||||
|
try {
|
||||||
|
return fn()
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user