add debug logs

This commit is contained in:
Raven Scott
2025-11-24 19:35:16 -05:00
parent ebd6512976
commit 9f6bbbd84f
2 changed files with 111 additions and 19 deletions
+97 -16
View File
@@ -1101,19 +1101,39 @@ async function loadVolumesForSelect(volumeId) {
const originalHandler = window.handlePeerResponse;
let volumesReceived = false;
const requestId = `volumes_${Date.now()}_${Math.random()}`;
const startTime = Date.now();
console.log('[DEBUG] Setting up volume handler with request ID:', requestId);
const volumeHandler = (response) => {
console.log('[DEBUG] Volume handler received response:', response);
const elapsed = Date.now() - startTime;
console.log(`[DEBUG] Volume handler received response after ${elapsed}ms`);
console.log('[DEBUG] Full response:', JSON.stringify(response));
console.log('[DEBUG] Response keys:', Object.keys(response || {}));
console.log('[DEBUG] Response success:', response?.success);
console.log('[DEBUG] Response volumes:', response?.volumes);
console.log('[DEBUG] Response type:', response?.type);
console.log('[DEBUG] Is volumes array?', Array.isArray(response?.volumes));
// Check if this is a volumes list response
// Log ALL responses to help debug
if (elapsed < 100) {
console.log('[DEBUG] Early response - might be from previous request');
}
// Check if this is a volumes list response - be more lenient
// Accept any response with volumes array or success + volumes
const isVolumesResponse =
(response.success === true && Array.isArray(response.volumes)) ||
(response.error && (response.error.includes('volume') || response.error.includes('Volume')));
(response && response.success === true && Array.isArray(response.volumes)) ||
(response && response.success === true && response.volumes !== undefined) ||
(response && response.error && (response.error.includes('volume') || response.error.includes('Volume'))) ||
(response && !response.type && Array.isArray(response.volumes)) ||
(response && response.type === 'volumes' && response.data);
console.log('[DEBUG] Is volumes response?', isVolumesResponse);
if (!isVolumesResponse) {
// Not a volumes response, pass to original handler
console.log('[DEBUG] Not a volumes response, passing to original handler');
if (typeof originalHandler === 'function') {
originalHandler(response);
}
@@ -1122,6 +1142,7 @@ async function loadVolumesForSelect(volumeId) {
if (volumesReceived) {
// Already processed, pass to original handler
console.log('[DEBUG] Already processed volumes response, passing to original handler');
if (typeof originalHandler === 'function') {
originalHandler(response);
}
@@ -1130,26 +1151,37 @@ async function loadVolumesForSelect(volumeId) {
console.log('[DEBUG] Processing volumes response');
// Handle success response
if (response.success === true && Array.isArray(response.volumes)) {
// Handle success response - check multiple formats
let volumesArray = null;
if (response && response.success === true && Array.isArray(response.volumes)) {
volumesArray = response.volumes;
} else if (response && response.type === 'volumes' && Array.isArray(response.data)) {
// Handle format from main volumes view
volumesArray = response.data;
} else if (response && Array.isArray(response.volumes)) {
volumesArray = response.volumes;
}
if (volumesArray !== null) {
volumesReceived = true;
window.handlePeerResponse = originalHandler;
console.log('[DEBUG] Adding volumes to select, count:', response.volumes.length);
console.log('[DEBUG] Adding volumes to select, count:', volumesArray.length);
// Clear and rebuild options
namedSelect.innerHTML = '<option value="">Select or create volume...</option>';
// Add existing volumes
if (response.volumes.length === 0) {
if (volumesArray.length === 0) {
const option = document.createElement('option');
option.value = '';
option.textContent = 'No volumes available';
option.disabled = true;
namedSelect.appendChild(option);
} else {
response.volumes.forEach(volume => {
const volumeName = volume.Name || volume.name || volume;
volumesArray.forEach(volume => {
const volumeName = volume.Name || volume.name || (typeof volume === 'string' ? volume : null);
if (volumeName) {
const option = document.createElement('option');
option.value = volumeName;
@@ -1161,9 +1193,10 @@ async function loadVolumesForSelect(volumeId) {
namedSelect.disabled = false;
console.log('[DEBUG] Volumes added to select successfully');
return;
}
// Handle error response
else if (response.error) {
else if (response && response.error) {
volumesReceived = true;
window.handlePeerResponse = originalHandler;
console.error('[ERROR] Failed to load volumes:', response.error);
@@ -1175,20 +1208,65 @@ async function loadVolumesForSelect(volumeId) {
option.disabled = true;
namedSelect.appendChild(option);
namedSelect.disabled = false;
} else {
// Unexpected format but might still be valid
console.warn('[WARN] Unexpected volumes response format:', response);
if (response && response.volumes !== undefined) {
volumesReceived = true;
window.handlePeerResponse = originalHandler;
const volumesArray = Array.isArray(response.volumes) ? response.volumes : [];
console.log('[DEBUG] Processing volumes in unexpected format, count:', volumesArray.length);
namedSelect.innerHTML = '<option value="">Select or create volume...</option>';
if (volumesArray.length === 0) {
const option = document.createElement('option');
option.value = '';
option.textContent = 'No volumes available';
option.disabled = true;
namedSelect.appendChild(option);
} else {
volumesArray.forEach(volume => {
const volumeName = volume.Name || volume.name || volume;
if (volumeName) {
const option = document.createElement('option');
option.value = volumeName;
option.textContent = volumeName;
namedSelect.appendChild(option);
}
});
}
namedSelect.disabled = false;
}
}
};
// Set the handler
// Set the handler BEFORE sending command
window.handlePeerResponse = volumeHandler;
console.log('[DEBUG] Volume handler set, ready to receive response');
// Send the command - always fetch fresh from server
console.log('[DEBUG] Sending listVolumes command to fetch fresh volumes list');
window.sendCommand('listVolumes');
try {
window.sendCommand('listVolumes');
console.log('[DEBUG] listVolumes command sent successfully');
} catch (error) {
console.error('[ERROR] Failed to send listVolumes command:', error);
window.handlePeerResponse = originalHandler;
namedSelect.innerHTML = '<option value="">Select or create volume...</option>';
const option = document.createElement('option');
option.value = '';
option.textContent = `Error: ${error.message}`;
option.disabled = true;
namedSelect.appendChild(option);
namedSelect.disabled = false;
return;
}
// Timeout after 5 seconds
// Timeout after 10 seconds (increased from 5)
const timeoutId = setTimeout(() => {
if (!volumesReceived) {
console.warn('[WARN] Volumes list request timed out');
console.warn('[WARN] Volumes list request timed out after 10 seconds');
console.warn('[WARN] Current handler:', window.handlePeerResponse === volumeHandler ? 'volumeHandler' : 'other');
window.handlePeerResponse = originalHandler;
volumesReceived = true; // Mark as received to prevent double handling
@@ -1200,7 +1278,7 @@ async function loadVolumesForSelect(volumeId) {
namedSelect.appendChild(option);
namedSelect.disabled = false;
}
}, 5000);
}, 10000);
} catch (error) {
console.error('[ERROR] Failed to load volumes:', error);
@@ -1214,6 +1292,9 @@ async function loadVolumesForSelect(volumeId) {
}
}
// Expose loadVolumesForSelect to window for inline handlers
window.loadVolumesForSelect = loadVolumesForSelect;
// Open file browser modal
let currentFileBrowserVolumeId = null;
let currentFileBrowserPath = '/';
+14 -3
View File
@@ -1134,13 +1134,16 @@ swarm.on('connection', (peer) => {
const volumes = await docker.listVolumes();
const volumesList = volumes.Volumes || [];
console.log(`[DEBUG] Found ${volumesList.length} volumes`);
console.log(`[DEBUG] Volume names:`, volumesList.map(v => v.Name || v.name).slice(0, 5));
// Return in the format expected by the frontend volume selector
// This handler is for the volume selector in deploy modal
response = { success: true, volumes: volumesList };
console.log(`[DEBUG] Sending volumes response with ${volumesList.length} volumes`);
console.log(`[DEBUG] Prepared volumes response with ${volumesList.length} volumes`);
console.log(`[DEBUG] Response will be sent:`, !!response);
} catch (error) {
console.error(`[ERROR] Failed to list volumes: ${error.message}`);
console.error(`[ERROR] Error stack:`, error.stack);
response = { success: false, error: `Failed to list volumes: ${error.message}` };
}
break;
@@ -1349,8 +1352,16 @@ swarm.on('connection', (peer) => {
// Send response if one was generated
if (response) {
console.log(`[DEBUG] Sending response to peer: ${JSON.stringify(response)}`);
peer.write(JSON.stringify(response));
const responseStr = JSON.stringify(response);
console.log(`[DEBUG] Sending response to peer (length: ${responseStr.length}):`, responseStr.substring(0, 200));
try {
peer.write(responseStr);
console.log(`[DEBUG] Response written to peer successfully`);
} catch (writeError) {
console.error(`[ERROR] Failed to write response to peer:`, writeError.message);
}
} else {
console.warn(`[WARN] No response generated for command: ${parsedData.command}`);
}
} catch (err) {
logger.error('Failed to handle data from peer', { error: err.message, command: parsedData?.command || 'unknown' });