Skip to content

fix script loading bug#103

Merged
9cb14c1ec0 merged 1 commit intomasterfrom
fix-path-bug
Oct 13, 2025
Merged

fix script loading bug#103
9cb14c1ec0 merged 1 commit intomasterfrom
fix-path-bug

Conversation

@9cb14c1ec0
Copy link
Copy Markdown
Collaborator

@9cb14c1ec0 9cb14c1ec0 commented Oct 13, 2025

Fixes # .

Changes proposed in this pull request

To test (it takes a while): npm install github:<username>/venom#<branch>

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability by properly awaiting file existence checks before loading required resources.
    • Resolved intermittent initialization issues that could occur when resources were read before being confirmed available.
    • Reduced rare startup failures and unexpected errors during setup, resulting in a more stable experience.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Oct 13, 2025

Walkthrough

Converted two internal file existence checks in src/api/whatsapp.ts to awaited asynchronous calls, ensuring the results are resolved before reading and loading wapi.js and middleware.js. No exported/public API signatures were modified.

Changes

Cohort / File(s) Summary
Async file checks in WhatsApp API
src/api/whatsapp.ts
Replaced synchronous-style usage of checkFileExists with awaited asynchronous calls before reading wapi.js and middleware.js; no exported API changes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant C as Caller
  participant WA as WhatsAppAPI
  participant FS as FileSystem
  rect rgb(240,245,255)
    note right of WA: New async control flow
    C->>WA: initialize/load
    WA->>FS: checkFileExists("wapi.js")
    FS-->>WA: Promise resolved (exists / not)
    alt exists
      WA->>FS: readFile("wapi.js")
      FS-->>WA: contents
    else not exists
      WA-->>C: handle missing wapi.js
    end
    WA->>FS: checkFileExists("middleware.js")
    FS-->>WA: Promise resolved (exists / not)
    alt exists
      WA->>FS: readFile("middleware.js")
      FS-->>WA: contents
    else not exists
      WA-->>C: handle missing middleware.js
    end
    WA-->>C: continue initialization
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

Thump-thump, my paws tap code so neat,
Await I must, before I read the sheet—
Wapi whispers, middleware hums,
Files exist? The promise comes.
Async burrows, control in flow,
Carrot-green lights—now off we go! 🥕✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title “fix script loading bug” directly conveys the primary change of resolving an issue with script loading in the codebase, which matches the conversion of file existence checks to asynchronous calls and the resulting control flow fix. It is concise, specific to the actual change, and clear enough for a reviewer scanning the history to understand the purpose of the pull request.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-path-bug

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/api/whatsapp.ts (1)

27-27: Consider removing or downgrading debug console logs.

The console.log statements in checkFileExists output on every file check. Consider removing them or using a proper logging framework with appropriate log levels to reduce noise in production environments.

Apply this diff to remove the debug logs:

 async function checkFileExists(filePath: string): Promise<boolean> {
   try {
     await fs.access(filePath, fs.constants.F_OK); // F_OK checks existence
-    console.log('File exists!');
     return true;
   } catch (error: unknown) {
     // Type the error as NodeJS.ErrnoException if needed for more specifics
-    console.log('File does not exist or is not accessible.');
     return false;
   }
 }

Also applies to: 31-31

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b512dd1 and 90836af.

📒 Files selected for processing (1)
  • src/api/whatsapp.ts (2 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-09-08T17:49:03.345Z
Learnt from: CR
PR: venomlib/venom#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-08T17:49:03.345Z
Learning: Applies to src/lib/wapi/**/*.js : WAPI layer code is built with webpack and injected into the Puppeteer browser context

Applied to files:

  • src/api/whatsapp.ts
📚 Learning: 2025-09-08T17:49:03.345Z
Learnt from: CR
PR: venomlib/venom#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-08T17:49:03.345Z
Learning: Applies to src/lib/wapi/functions/**/*.js : WAPI functions in src/lib/wapi/functions are JavaScript files injected into the browser; after changing them, run `npm run build:wapi` to rebuild

Applied to files:

  • src/api/whatsapp.ts
🔇 Additional comments (2)
src/api/whatsapp.ts (2)

87-89: LGTM! Critical bug fix for file path resolution.

The addition of await correctly resolves the Promise returned by checkFileExists. Without it, the condition would always be truthy (a Promise object is truthy in JavaScript), causing the code to always attempt reading from the first path regardless of file existence, which would fail when running from node_modules.


112-114: LGTM! Critical bug fix for middleware path resolution.

Consistent with the wapi.js fix above, this correctly awaits the file existence check before deciding which path to use for reading the middleware script.

@9cb14c1ec0 9cb14c1ec0 merged commit 688e741 into master Oct 13, 2025
3 checks passed
@9cb14c1ec0 9cb14c1ec0 deleted the fix-path-bug branch October 13, 2025 17:31
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