MCPcopy Create free account
hub / github.com/Coneja-Chibi/CarrotKernel / initializePackManagerWithRetry

Function initializePackManagerWithRetry

index.js:7084–7145  ·  view source on GitHub ↗
(retries = 3, delay = 1000)

Source from the content-addressed store, hash-verified

7082
7083 async function initializePackManagerWithRetry(retries = 3, delay = 1000) {
7084 for (let attempt = 1; attempt <= retries; attempt++) {
7085 try {
7086 CarrotDebug.repo(`Initialization attempt ${attempt}/${retries}`);
7087
7088 // Clear any existing instance
7089 if (window.CarrotPackManager) {
7090 CarrotDebug.repo('Clearing existing CarrotPackManager instance');
7091 delete window.CarrotPackManager;
7092 }
7093
7094 window.CarrotPackManager = new CarrotPackManager();
7095 CarrotDebug.repo('CarrotPackManager created successfully');
7096
7097 window.CarrotPackManager.loadLocalPacks();
7098 CarrotDebug.repo('Local packs loaded');
7099
7100 // Verify the instance is properly set up
7101 const verification = {
7102 exists: !!window.CarrotPackManager,
7103 hasScanMethod: typeof window.CarrotPackManager.scanRemotePacks === 'function',
7104 hasLoadMethod: typeof window.CarrotPackManager.loadLocalPacks === 'function',
7105 githubRepo: window.CarrotPackManager.githubRepo,
7106 packsFolder: window.CarrotPackManager.packsFolder
7107 };
7108
7109 CarrotDebug.repo('CarrotPackManager verification:', verification);
7110
7111 // Validate that all required components are working
7112 if (!verification.exists || !verification.hasScanMethod || !verification.hasLoadMethod) {
7113 throw new Error('CarrotPackManager initialization incomplete');
7114 }
7115
7116 CarrotDebug.repo('✅ CarrotPackManager initialized successfully on attempt', attempt);
7117 return true;
7118
7119 } catch (error) {
7120 CarrotDebug.error(`Initialization attempt ${attempt} failed:`, error);
7121
7122 if (attempt < retries) {
7123 CarrotDebug.repo(`Retrying in ${delay}ms...`);
7124 await new Promise(resolve => setTimeout(resolve, delay));
7125 delay *= 2; // Exponential backoff
7126 } else {
7127 CarrotDebug.error('All initialization attempts failed');
7128
7129 // Provide user-visible error
7130 setTimeout(() => {
7131 if ($('#carrot-pack-status').length) {
7132 $('#carrot-pack-status').html(`
7133 <p>❌ Pack Manager failed to initialize after ${retries} attempts.</p>
7134 <p>🔄 <button onclick="location.reload()" class="menu_button">Refresh Page</button></p>
7135 <p>💻 Open console for detailed error logs</p>
7136 `);
7137 }
7138 }, 2000);
7139
7140 return false;
7141 }

Callers 1

index.jsFile · 0.85

Calls 3

repoMethod · 0.80
loadLocalPacksMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected