@@ -77,6 +77,7 @@ import { WordGenError } from "../utils/word-gen-error";
7777import { tryCatch } from "@monkeytype/util/trycatch" ;
7878import { captureException } from "../sentry" ;
7979import * as Loader from "../elements/loader" ;
80+ import * as TestInitFailed from "../elements/test-init-failed" ;
8081
8182let failReason = "" ;
8283const koInputVisual = document . getElementById ( "koInputVisual" ) as HTMLElement ;
@@ -338,7 +339,15 @@ export function restart(options = {} as RestartOptions): void {
338339
339340 TestState . setRepeated ( options . withSameWordset ?? false ) ;
340341 TestState . setPaceRepeat ( repeatWithPace ) ;
341- await init ( ) ;
342+ TestInitFailed . hide ( ) ;
343+ TestState . setTestInitSuccess ( true ) ;
344+ const initResult = await init ( ) ;
345+
346+ if ( initResult === null ) {
347+ TestUI . setTestRestarting ( false ) ;
348+ return ;
349+ }
350+
342351 await PaceCaret . init ( ) ;
343352
344353 for ( const fb of getActiveFunboxesWithFunction ( "restart" ) ) {
@@ -385,22 +394,28 @@ export function restart(options = {} as RestartOptions): void {
385394let lastInitError : Error | null = null ;
386395let rememberLazyMode : boolean ;
387396let testReinitCount = 0 ;
388- export async function init ( ) : Promise < void > {
397+ export async function init ( ) : Promise < void | null > {
389398 console . debug ( "Initializing test" ) ;
390399 testReinitCount ++ ;
391- if ( testReinitCount >= 4 ) {
400+ if ( testReinitCount > 3 ) {
392401 if ( lastInitError ) {
393402 captureException ( lastInitError ) ;
403+ TestInitFailed . showError (
404+ `${ lastInitError . name } : ${ lastInitError . message } `
405+ ) ;
394406 }
407+ TestInitFailed . show ( ) ;
395408 TestUI . setTestRestarting ( false ) ;
396- Notifications . add (
397- "Too many test reinitialization attempts. Something is going very wrong. Please contact support." ,
398- - 1 ,
399- {
400- important : true ,
401- }
402- ) ;
403- return ;
409+ TestState . setTestInitSuccess ( false ) ;
410+ Focus . set ( false ) ;
411+ // Notifications.add(
412+ // "Too many test reinitialization attempts. Something is going very wrong. Please contact support.",
413+ // -1,
414+ // {
415+ // important: true,
416+ // }
417+ // );
418+ return null ;
404419 }
405420
406421 MonkeyPower . reset ( ) ;
@@ -426,8 +441,7 @@ export async function init(): Promise<void> {
426441
427442 if ( ! language || language . name !== Config . language ) {
428443 UpdateConfig . setLanguage ( "english" ) ;
429- await init ( ) ;
430- return ;
444+ return await init ( ) ;
431445 }
432446
433447 if ( ActivePage . get ( ) === "test" ) {
@@ -492,6 +506,7 @@ export async function init(): Promise<void> {
492506 wordsHaveTab = gen . hasTab ;
493507 wordsHaveNewline = gen . hasNewline ;
494508 } catch ( e ) {
509+ Loader . hide ( ) ;
495510 if ( e instanceof WordGenError || e instanceof Error ) {
496511 lastInitError = e ;
497512 }
@@ -512,8 +527,7 @@ export async function init(): Promise<void> {
512527 ) ;
513528 }
514529
515- await init ( ) ;
516- return ;
530+ return await init ( ) ;
517531 }
518532
519533 const beforeHasNumbers = TestWords . hasNumbers ;
@@ -1348,6 +1362,10 @@ $(".pageTest").on("click", "#testModesNotice .textButton.restart", () => {
13481362 restart ( ) ;
13491363} ) ;
13501364
1365+ $ ( ".pageTest" ) . on ( "click" , "#testInitFailed button.restart" , ( ) => {
1366+ restart ( ) ;
1367+ } ) ;
1368+
13511369$ ( ".pageTest" ) . on ( "click" , "#restartTestButton" , ( ) => {
13521370 ManualRestart . set ( ) ;
13531371 if ( TestUI . resultCalculating ) return ;
0 commit comments