File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -34,6 +34,16 @@ async function getBrowserPage(): Promise<import('./types.js').IPage> {
3434 return bridge . connect ( { timeout : 30 , workspace : 'browser:default' } ) ;
3535}
3636
37+ function parsePositiveIntOption ( val : string | undefined , label : string , fallback : number ) : number {
38+ if ( val === undefined ) return fallback ;
39+ const parsed = parseInt ( val , 10 ) ;
40+ if ( Number . isNaN ( parsed ) || parsed <= 0 ) {
41+ console . error ( `[cli] Invalid ${ label } ="${ val } ", using default ${ fallback } ` ) ;
42+ return fallback ;
43+ }
44+ return parsed ;
45+ }
46+
3747function applyVerbose ( opts : { verbose ?: boolean } ) : void {
3848 if ( opts . verbose ) process . env . OPENCLI_VERBOSE = '1' ;
3949}
@@ -1132,10 +1142,9 @@ cli({
11321142 . action ( async ( opts ) => {
11331143 // @ts -expect-error JS adapter — no type declarations
11341144 const { startServe } = await import ( '../clis/antigravity/serve.js' ) ;
1135- const { parseTimeoutValue } = await import ( './runtime.js' ) ;
11361145 await startServe ( {
11371146 port : parseInt ( opts . port , 10 ) ,
1138- timeout : opts . timeout ? parseTimeoutValue ( opts . timeout , '--timeout' , 120 ) : undefined ,
1147+ timeout : opts . timeout ? parsePositiveIntOption ( opts . timeout , '--timeout' , 120 ) : undefined ,
11391148 } ) ;
11401149 } ) ;
11411150
Original file line number Diff line number Diff line change @@ -13,23 +13,17 @@ export function getBrowserFactory(site?: string): new () => IBrowserFactory {
1313 return BrowserBridge ;
1414}
1515
16- /**
17- * Validates and parses a timeout value (seconds).
18- */
19- export function parseTimeoutValue ( val : string | number | undefined , label : string , fallback : number ) : number {
20- if ( val === undefined ) return fallback ;
21- const parsed = typeof val === 'number' ? val : parseInt ( String ( val ) , 10 ) ;
16+ function parseEnvTimeout ( envVar : string , fallback : number ) : number {
17+ const raw = process . env [ envVar ] ;
18+ if ( raw === undefined ) return fallback ;
19+ const parsed = parseInt ( raw , 10 ) ;
2220 if ( Number . isNaN ( parsed ) || parsed <= 0 ) {
23- console . error ( `[runtime] Invalid ${ label } ="${ val } ", using default ${ fallback } s` ) ;
21+ log . warn ( `[runtime] Invalid ${ envVar } ="${ raw } ", using default ${ fallback } s` ) ;
2422 return fallback ;
2523 }
2624 return parsed ;
2725}
2826
29- export function parseEnvTimeout ( envVar : string , fallback : number ) : number {
30- return parseTimeoutValue ( process . env [ envVar ] , envVar , fallback ) ;
31- }
32-
3327export const DEFAULT_BROWSER_CONNECT_TIMEOUT = parseEnvTimeout ( 'OPENCLI_BROWSER_CONNECT_TIMEOUT' , 30 ) ;
3428export const DEFAULT_BROWSER_COMMAND_TIMEOUT = parseEnvTimeout ( 'OPENCLI_BROWSER_COMMAND_TIMEOUT' , 60 ) ;
3529export const DEFAULT_BROWSER_EXPLORE_TIMEOUT = parseEnvTimeout ( 'OPENCLI_BROWSER_EXPLORE_TIMEOUT' , 120 ) ;
You can’t perform that action at this time.
0 commit comments