File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -205,6 +205,14 @@ function remoteDetailKind(detail: unknown): RemoteDetailKind {
205205 }
206206}
207207
208+ const readRemoteTimeoutMs = ( detail : unknown ) : number | undefined => {
209+ if ( typeof detail !== "object" || detail === null || ! ( "timeoutMs" in detail ) ) return undefined ;
210+ const timeoutMs = detail . timeoutMs ;
211+ return typeof timeoutMs === "number" && Number . isInteger ( timeoutMs ) && timeoutMs > 0
212+ ? timeoutMs
213+ : undefined ;
214+ } ;
215+
208216const MAX_REASON_CHARS = 500 ;
209217
210218const classifyResponseError = (
@@ -253,11 +261,16 @@ const classifyResponseError = (
253261 ...context ,
254262 ...remoteDiagnostics ,
255263 } ) ;
256- case "PreviewAutomationTimeoutError" :
264+ case "PreviewAutomationTimeoutError" : {
265+ const remoteTimeoutMs = readRemoteTimeoutMs ( error . detail ) ;
257266 return new PreviewAutomationTimeoutError ( {
258267 ...context ,
259268 ...remoteDiagnostics ,
269+ ...( remoteTimeoutMs === undefined
270+ ? { }
271+ : { timeoutMs : Math . min ( context . timeoutMs , remoteTimeoutMs ) } ) ,
260272 } ) ;
273+ }
261274 case "PreviewAutomationControlInterruptedError" : {
262275 const reason = decodeControlReason ( error . detail ) ;
263276 return new PreviewAutomationControlInterruptedError ( {
Original file line number Diff line number Diff line change @@ -379,6 +379,37 @@ beforeEach(() => {
379379 desktopConnections . length = 0 ;
380380} ) ;
381381
382+ it . live ( "preview_open reports its navigation timeout instead of the request budget" , ( ) =>
383+ Effect . scoped (
384+ Effect . gen ( function * ( ) {
385+ const { broker } = yield * ready ;
386+ initialNavigation = async ( ) => {
387+ throw Object . assign ( new Error ( "page.goto: Timeout 15000ms exceeded." ) , {
388+ name : "TimeoutError" ,
389+ } ) ;
390+ } ;
391+
392+ const error = yield * broker
393+ . invoke < PreviewAutomationStatus > ( {
394+ scope,
395+ operation : "open" ,
396+ input : {
397+ url : "http://localhost:1337/" ,
398+ reuseExistingTab : false ,
399+ show : false ,
400+ } ,
401+ } )
402+ . pipe ( Effect . flip ) ;
403+
404+ expect ( error ) . toMatchObject ( {
405+ _tag : "PreviewAutomationTimeoutError" ,
406+ timeoutMs : 15_000 ,
407+ } ) ;
408+ expect ( error . message ) . toBe ( "Preview automation open timed out after 15000ms." ) ;
409+ } ) ,
410+ ) . pipe ( Effect . provide ( layer ) ) ,
411+ ) ;
412+
382413it . live . each ( [ "desktop" as const , undefined ] ) (
383414 "explicit desktop targets ($0 runtime) fail without creating a server tab" ,
384415 ( runtime ) =>
Original file line number Diff line number Diff line change @@ -902,7 +902,9 @@ const make = Effect.gen(function* () {
902902 ( desktop || adopted ) && page . url ( ) === snapshot . navStatus . url
903903 ? page . reload ( options )
904904 : page . goto ( snapshot . navStatus . url , options )
905- ) . then ( constVoid ) ;
905+ ) . then ( constVoid , ( cause : unknown ) => {
906+ throw ServerBrowserPage . toOperationError ( cause , NAVIGATION_TIMEOUT_MS ) ;
907+ } ) ;
906908
907909 if ( tab . control . agentId !== null ) tab . control . track ( tab . initialNavigation ) ;
908910 else void tab . initialNavigation . catch ( constVoid ) ;
@@ -1458,7 +1460,7 @@ const make = Effect.gen(function* () {
14581460 `Navigation to ${ url } failed: ${ ServerBrowserPage . parseNetError ( message ) . description } ` ,
14591461 ) ;
14601462 }
1461- throw cause ;
1463+ throw ServerBrowserPage . toOperationError ( cause , timeout ) ;
14621464 } ) ;
14631465 } ;
14641466
Original file line number Diff line number Diff line change @@ -40,7 +40,10 @@ export class ServerBrowserOperationError extends Error {
4040 }
4141}
4242
43- export const toOperationError = ( cause : unknown ) : ServerBrowserOperationError => {
43+ export const toOperationError = (
44+ cause : unknown ,
45+ timeoutMs ?: number ,
46+ ) : ServerBrowserOperationError => {
4447 if ( cause instanceof BrowserControlInterrupted )
4548 return new ServerBrowserOperationError (
4649 "PreviewAutomationControlInterruptedError" ,
@@ -51,7 +54,11 @@ export const toOperationError = (cause: unknown): ServerBrowserOperationError =>
5154 const message = cause instanceof Error ? cause . message : String ( cause ) ;
5255 const firstLine = message . split ( "\n" ) [ 0 ] ?? message ;
5356 if ( cause instanceof Error && cause . name === "TimeoutError" ) {
54- return new ServerBrowserOperationError ( "PreviewAutomationTimeoutError" , firstLine ) ;
57+ return new ServerBrowserOperationError (
58+ "PreviewAutomationTimeoutError" ,
59+ firstLine ,
60+ timeoutMs === undefined ? undefined : { timeoutMs } ,
61+ ) ;
5562 }
5663 if (
5764 / w h i l e p a r s i n g s e l e c t o r | U n k n o w n e n g i n e | U n e x p e c t e d t o k e n | s t r i c t m o d e v i o l a t i o n / i. test ( message )
You can’t perform that action at this time.
0 commit comments