add debug logs
This commit is contained in:
+97
-16
@@ -1101,19 +1101,39 @@ async function loadVolumesForSelect(volumeId) {
|
|||||||
const originalHandler = window.handlePeerResponse;
|
const originalHandler = window.handlePeerResponse;
|
||||||
let volumesReceived = false;
|
let volumesReceived = false;
|
||||||
const requestId = `volumes_${Date.now()}_${Math.random()}`;
|
const requestId = `volumes_${Date.now()}_${Math.random()}`;
|
||||||
|
const startTime = Date.now();
|
||||||
|
|
||||||
console.log('[DEBUG] Setting up volume handler with request ID:', requestId);
|
console.log('[DEBUG] Setting up volume handler with request ID:', requestId);
|
||||||
|
|
||||||
const volumeHandler = (response) => {
|
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 =
|
const isVolumesResponse =
|
||||||
(response.success === true && Array.isArray(response.volumes)) ||
|
(response && response.success === true && Array.isArray(response.volumes)) ||
|
||||||
(response.error && (response.error.includes('volume') || response.error.includes('Volume')));
|
(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) {
|
if (!isVolumesResponse) {
|
||||||
// Not a volumes response, pass to original handler
|
// Not a volumes response, pass to original handler
|
||||||
|
console.log('[DEBUG] Not a volumes response, passing to original handler');
|
||||||
if (typeof originalHandler === 'function') {
|
if (typeof originalHandler === 'function') {
|
||||||
originalHandler(response);
|
originalHandler(response);
|
||||||
}
|
}
|
||||||
@@ -1122,6 +1142,7 @@ async function loadVolumesForSelect(volumeId) {
|
|||||||
|
|
||||||
if (volumesReceived) {
|
if (volumesReceived) {
|
||||||
// Already processed, pass to original handler
|
// Already processed, pass to original handler
|
||||||
|
console.log('[DEBUG] Already processed volumes response, passing to original handler');
|
||||||
if (typeof originalHandler === 'function') {
|
if (typeof originalHandler === 'function') {
|
||||||
originalHandler(response);
|
originalHandler(response);
|
||||||
}
|
}
|
||||||
@@ -1130,26 +1151,37 @@ async function loadVolumesForSelect(volumeId) {
|
|||||||
|
|
||||||
console.log('[DEBUG] Processing volumes response');
|
console.log('[DEBUG] Processing volumes response');
|
||||||
|
|
||||||
// Handle success response
|
// Handle success response - check multiple formats
|
||||||
if (response.success === true && Array.isArray(response.volumes)) {
|
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;
|
volumesReceived = true;
|
||||||
window.handlePeerResponse = originalHandler;
|
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
|
// Clear and rebuild options
|
||||||
namedSelect.innerHTML = '<option value="">Select or create volume...</option>';
|
namedSelect.innerHTML = '<option value="">Select or create volume...</option>';
|
||||||
|
|
||||||
// Add existing volumes
|
// Add existing volumes
|
||||||
if (response.volumes.length === 0) {
|
if (volumesArray.length === 0) {
|
||||||
const option = document.createElement('option');
|
const option = document.createElement('option');
|
||||||
option.value = '';
|
option.value = '';
|
||||||
option.textContent = 'No volumes available';
|
option.textContent = 'No volumes available';
|
||||||
option.disabled = true;
|
option.disabled = true;
|
||||||
namedSelect.appendChild(option);
|
namedSelect.appendChild(option);
|
||||||
} else {
|
} else {
|
||||||
response.volumes.forEach(volume => {
|
volumesArray.forEach(volume => {
|
||||||
const volumeName = volume.Name || volume.name || volume;
|
const volumeName = volume.Name || volume.name || (typeof volume === 'string' ? volume : null);
|
||||||
if (volumeName) {
|
if (volumeName) {
|
||||||
const option = document.createElement('option');
|
const option = document.createElement('option');
|
||||||
option.value = volumeName;
|
option.value = volumeName;
|
||||||
@@ -1161,9 +1193,10 @@ async function loadVolumesForSelect(volumeId) {
|
|||||||
|
|
||||||
namedSelect.disabled = false;
|
namedSelect.disabled = false;
|
||||||
console.log('[DEBUG] Volumes added to select successfully');
|
console.log('[DEBUG] Volumes added to select successfully');
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
// Handle error response
|
// Handle error response
|
||||||
else if (response.error) {
|
else if (response && response.error) {
|
||||||
volumesReceived = true;
|
volumesReceived = true;
|
||||||
window.handlePeerResponse = originalHandler;
|
window.handlePeerResponse = originalHandler;
|
||||||
console.error('[ERROR] Failed to load volumes:', response.error);
|
console.error('[ERROR] Failed to load volumes:', response.error);
|
||||||
@@ -1175,20 +1208,65 @@ async function loadVolumesForSelect(volumeId) {
|
|||||||
option.disabled = true;
|
option.disabled = true;
|
||||||
namedSelect.appendChild(option);
|
namedSelect.appendChild(option);
|
||||||
namedSelect.disabled = false;
|
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;
|
window.handlePeerResponse = volumeHandler;
|
||||||
|
console.log('[DEBUG] Volume handler set, ready to receive response');
|
||||||
|
|
||||||
// Send the command - always fetch fresh from server
|
// Send the command - always fetch fresh from server
|
||||||
console.log('[DEBUG] Sending listVolumes command to fetch fresh volumes list');
|
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(() => {
|
const timeoutId = setTimeout(() => {
|
||||||
if (!volumesReceived) {
|
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;
|
window.handlePeerResponse = originalHandler;
|
||||||
volumesReceived = true; // Mark as received to prevent double handling
|
volumesReceived = true; // Mark as received to prevent double handling
|
||||||
|
|
||||||
@@ -1200,7 +1278,7 @@ async function loadVolumesForSelect(volumeId) {
|
|||||||
namedSelect.appendChild(option);
|
namedSelect.appendChild(option);
|
||||||
namedSelect.disabled = false;
|
namedSelect.disabled = false;
|
||||||
}
|
}
|
||||||
}, 5000);
|
}, 10000);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('[ERROR] Failed to load volumes:', 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
|
// Open file browser modal
|
||||||
let currentFileBrowserVolumeId = null;
|
let currentFileBrowserVolumeId = null;
|
||||||
let currentFileBrowserPath = '/';
|
let currentFileBrowserPath = '/';
|
||||||
|
|||||||
+14
-3
@@ -1134,13 +1134,16 @@ swarm.on('connection', (peer) => {
|
|||||||
const volumes = await docker.listVolumes();
|
const volumes = await docker.listVolumes();
|
||||||
const volumesList = volumes.Volumes || [];
|
const volumesList = volumes.Volumes || [];
|
||||||
console.log(`[DEBUG] Found ${volumesList.length} 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
|
// Return in the format expected by the frontend volume selector
|
||||||
// This handler is for the volume selector in deploy modal
|
// This handler is for the volume selector in deploy modal
|
||||||
response = { success: true, volumes: volumesList };
|
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) {
|
} catch (error) {
|
||||||
console.error(`[ERROR] Failed to list volumes: ${error.message}`);
|
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}` };
|
response = { success: false, error: `Failed to list volumes: ${error.message}` };
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -1349,8 +1352,16 @@ swarm.on('connection', (peer) => {
|
|||||||
|
|
||||||
// Send response if one was generated
|
// Send response if one was generated
|
||||||
if (response) {
|
if (response) {
|
||||||
console.log(`[DEBUG] Sending response to peer: ${JSON.stringify(response)}`);
|
const responseStr = JSON.stringify(response);
|
||||||
peer.write(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) {
|
} catch (err) {
|
||||||
logger.error('Failed to handle data from peer', { error: err.message, command: parsedData?.command || 'unknown' });
|
logger.error('Failed to handle data from peer', { error: err.message, command: parsedData?.command || 'unknown' });
|
||||||
|
|||||||
Reference in New Issue
Block a user