Skip to content

Show actionable error when Slack locks cookie database#32

Merged
devxoul merged 2 commits intomainfrom
fix/slack-cookie-lock-error
Mar 5, 2026
Merged

Show actionable error when Slack locks cookie database#32
devxoul merged 2 commits intomainfrom
fix/slack-cookie-lock-error

Conversation

@devxoul
Copy link
Owner

@devxoul devxoul commented Mar 5, 2026

Summary

When the Slack desktop app is running, it holds an EBUSY lock on the Cookies SQLite file. copyFileSync fails silently, returning an empty cookie — leading to confusing "No workspace configured" or "Extracted tokens are invalid" errors with no hint about the actual cause. Now the EBUSY error is detected and surfaces a clear message telling the user to quit Slack and retry.

Changes

token-extractor.ts

  • Catch EBUSY from copyFileSync in readCookieFromDB() and throw with a descriptive message instead of silently returning ''.

ensure-auth.ts

  • Propagate cookie-lock errors instead of swallowing them in the catch-all. Other extraction errors (e.g. Slack not installed) are still silently ignored.

Before

$ agent-slack auth status
{"error":"No workspace configured. Run \"auth extract\" first."}

After

$ agent-slack auth status
{"error":"Failed to read Slack cookies. The Slack app is currently running and locking the cookie database. Quit the Slack app completely and try again."}

Verification

  • bun typecheck — clean.
  • bun test — 852 pass, 0 fail.

Summary by cubic

Shows a clear, actionable error when the Slack app locks the cookies database (EBUSY), telling users to quit Slack and try again. Prevents silent failures that caused “No workspace configured” or “invalid token” messages.

  • Bug Fixes
    • Detects EBUSY during cookie DB copy and throws a helpful message.
    • ensureSlackAuth only extracts when no workspace is set and propagates cookie-lock errors; other extraction errors remain ignored.

Written for commit f0f51e3. Summary will update on new commits.

@vercel
Copy link

vercel bot commented Mar 5, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
agent-messenger Ignored Ignored Mar 5, 2026 5:47am

Request Review

devxoul and others added 2 commits March 5, 2026 14:46
Previously copyFileSync failures were silently swallowed, returning an
empty cookie string that led to confusing 'invalid token' errors. Now
EBUSY is detected and throws with a message telling the user to quit
the Slack app.

Co-authored-by: JaeKyu Jin <iowm0818@naver.com>
ensureSlackAuth previously swallowed all extraction errors silently.
Now EBUSY / cookie-lock errors propagate so the user sees the
actionable message on any command, not just 'auth extract'.

Co-authored-by: JaeKyu Jin <iowm0818@naver.com>
@devxoul devxoul force-pushed the fix/slack-cookie-lock-error branch from aa28192 to f0f51e3 Compare March 5, 2026 05:47
@devxoul devxoul merged commit ac5cfe4 into main Mar 5, 2026
4 checks passed
@devxoul devxoul deleted the fix/slack-cookie-lock-error branch March 5, 2026 05:48
Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 4 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/platforms/slack/token-extractor.test.ts">

<violation number="1" location="src/platforms/slack/token-extractor.test.ts:156">
P2: Restore the `copyFileSync` spy in a `finally` block to avoid leaking a global fs mock when the assertion fails.</violation>
</file>

<file name="src/platforms/slack/ensure-auth.ts">

<violation number="1" location="src/platforms/slack/ensure-auth.ts:30">
P2: The new cookie-lock check can throw inside the catch block when `error` is not an `Error` object, which can mask the original exception.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment on lines +156 to +159
const extractor = new TokenExtractor('darwin', slackDir)
await expect(extractor.extract()).rejects.toThrow('Quit the Slack app completely and try again')

copyFileSyncSpy.mockRestore()
Copy link

@cubic-dev-ai cubic-dev-ai bot Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Restore the copyFileSync spy in a finally block to avoid leaking a global fs mock when the assertion fails.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/platforms/slack/token-extractor.test.ts, line 156:

<comment>Restore the `copyFileSync` spy in a `finally` block to avoid leaking a global fs mock when the assertion fails.</comment>

<file context>
@@ -133,6 +134,31 @@ describe('TokenExtractor Windows DPAPI', () => {
+    })
+
+    // when — then
+    const extractor = new TokenExtractor('darwin', slackDir)
+    await expect(extractor.extract()).rejects.toThrow('Quit the Slack app completely and try again')
+
</file context>
Suggested change
const extractor = new TokenExtractor('darwin', slackDir)
await expect(extractor.extract()).rejects.toThrow('Quit the Slack app completely and try again')
copyFileSyncSpy.mockRestore()
try {
const extractor = new TokenExtractor('darwin', slackDir)
await expect(extractor.extract()).rejects.toThrow('Quit the Slack app completely and try again')
} finally {
copyFileSyncSpy.mockRestore()
}
Fix with Cubic

}
} catch {}
} catch (error) {
if ((error as NodeJS.ErrnoException).code === 'EBUSY' || (error as Error).message.includes('locking the cookie')) {
Copy link

@cubic-dev-ai cubic-dev-ai bot Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The new cookie-lock check can throw inside the catch block when error is not an Error object, which can mask the original exception.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/platforms/slack/ensure-auth.ts, line 30:

<comment>The new cookie-lock check can throw inside the catch block when `error` is not an `Error` object, which can mask the original exception.</comment>

<file context>
@@ -26,5 +26,10 @@ export async function ensureSlackAuth(): Promise<void> {
     }
-  } catch {}
+  } catch (error) {
+    if ((error as NodeJS.ErrnoException).code === 'EBUSY' || (error as Error).message.includes('locking the cookie')) {
+      throw error
+    }
</file context>
Suggested change
if ((error as NodeJS.ErrnoException).code === 'EBUSY' || (error as Error).message.includes('locking the cookie')) {
const code = typeof error === 'object' && error !== null ? (error as NodeJS.ErrnoException).code : undefined
const message = error instanceof Error ? error.message : String(error)
if (code === 'EBUSY' || message.includes('locking the cookie')) {
Fix with Cubic

devxoul added a commit that referenced this pull request Mar 5, 2026
Fix spy leak and unsafe error cast from PR #32 review
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant