-
Notifications
You must be signed in to change notification settings - Fork 6
fix: handle missing docker-compose.yml during cleanup gracefully #741
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1301,11 +1301,36 @@ export async function stopContainers(workDir: string, keepContainers: boolean): | |
| logger.info('Stopping containers...'); | ||
|
|
||
| try { | ||
| await execa('docker', ['compose', 'down', '-v'], { | ||
| cwd: workDir, | ||
| stdio: 'inherit', | ||
| }); | ||
| logger.success('Containers stopped successfully'); | ||
| // Check if workDir and docker-compose.yml exist before using docker compose | ||
| const composeFile = path.join(workDir, 'docker-compose.yml'); | ||
| if (fs.existsSync(workDir) && fs.existsSync(composeFile)) { | ||
| // Normal path: use docker compose down | ||
| await execa('docker', ['compose', 'down', '-v'], { | ||
| cwd: workDir, | ||
| stdio: 'inherit', | ||
| }); | ||
| logger.success('Containers stopped successfully'); | ||
| } else { | ||
| // Fallback: compose file missing, stop containers by name | ||
| logger.debug('Compose file not found, stopping containers by name'); | ||
|
|
||
| // Stop and remove containers by name | ||
| const containerNames = ['awf-agent', 'awf-squid']; | ||
| for (const name of containerNames) { | ||
| try { | ||
| // Check if container exists | ||
| const { stdout } = await execa('docker', ['ps', '-aq', '-f', `name=^${name}$`]); | ||
| if (stdout.trim()) { | ||
| logger.debug(`Stopping container: ${name}`); | ||
| await execa('docker', ['rm', '-f', name], { stdio: 'inherit' }); | ||
| } | ||
| } catch (err) { | ||
| logger.debug(`Could not stop container ${name}:`, err); | ||
| } | ||
| } | ||
|
|
||
| logger.success('Containers stopped successfully'); | ||
| } | ||
|
Comment on lines
+1304
to
+1333
|
||
| } catch (error) { | ||
| logger.error('Failed to stop containers:', error); | ||
| throw error; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error handling in the fallback path swallows all errors with individual try-catch blocks (lines 1320-1329). This means if both containers fail to stop (e.g., Docker daemon is down), the function will still log "Containers stopped successfully" and return without error.
Consider tracking whether at least one container operation succeeded, or accumulating errors and throwing if no containers could be stopped. For example:
This ensures the outer error handler and calling code are aware when cleanup truly fails.