-
-
Notifications
You must be signed in to change notification settings - Fork 176
Undefined filename in require #168
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
base: main
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -17,8 +17,6 @@ | |
| * It's used by virtually all other modules for status reporting and error logging. | ||
| */ | ||
|
|
||
| import { createRequire } from 'node:module'; | ||
| import { resolve } from 'node:path'; | ||
| // Note: Removed "import * as Sentry from '@sentry/node'" to prevent native module loading at import time | ||
|
|
||
| const SENTRY_ENABLED = | ||
|
|
@@ -58,16 +56,17 @@ function isTestEnv(): boolean { | |
|
|
||
| type SentryModule = typeof import('@sentry/node'); | ||
|
|
||
| const require = createRequire( | ||
| typeof __filename === 'string' ? __filename : resolve(process.cwd(), 'package.json'), | ||
| ); | ||
| let cachedSentry: SentryModule | null = null; | ||
| let sentryLoadAttempted = false; | ||
|
|
||
| function loadSentrySync(): SentryModule | null { | ||
| async function loadSentryAsync(): Promise<SentryModule | null> { | ||
| if (!SENTRY_ENABLED || isTestEnv()) return null; | ||
| if (cachedSentry) return cachedSentry; | ||
| if (sentryLoadAttempted) return null; | ||
|
|
||
| sentryLoadAttempted = true; | ||
| try { | ||
| cachedSentry = require('@sentry/node') as SentryModule; | ||
| cachedSentry = await import('@sentry/node'); | ||
| return cachedSentry; | ||
| } catch { | ||
| // If @sentry/node is not installed in some environments, fail silently. | ||
|
Comment on lines
63
to
72
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: The switch to asynchronous Sentry loading in 🔍 Detailed AnalysisThe 💡 Suggested FixRevert 🤖 Prompt for AI AgentDid we get this right? 👍 / 👎 to inform future reviews. |
||
|
|
@@ -76,13 +75,20 @@ function loadSentrySync(): SentryModule | null { | |
| } | ||
|
|
||
| function withSentry(cb: (s: SentryModule) => void): void { | ||
| const s = loadSentrySync(); | ||
| if (!s) return; | ||
| try { | ||
| cb(s); | ||
| } catch { | ||
| // no-op: avoid throwing inside logger | ||
| } | ||
| // Fire-and-forget async Sentry loading | ||
| loadSentryAsync() | ||
| .then((s) => { | ||
| if (s) { | ||
| try { | ||
| cb(s); | ||
| } catch { | ||
| // no-op: avoid throwing inside logger | ||
| } | ||
| } | ||
| }) | ||
| .catch(() => { | ||
| // no-op: avoid throwing inside logger | ||
| }); | ||
| } | ||
|
|
||
| if (!SENTRY_ENABLED) { | ||
|
|
||
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.
Early calls during Sentry loading silently dropped
Medium Severity
The
loadSentryAsyncfunction setssentryLoadAttempted = truebefore the asyncimport()completes. Any log calls that occur while the first import is still in progress will findsentryLoadAttemptedistruebutcachedSentryis stillnull, causing the function to returnnullimmediately. This means error messages logged during the Sentry loading window are silently lost and never sent to Sentry. The loading promise could be stored and returned to subsequent callers to ensure all callbacks execute once loading completes.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.
@cursor fix
Uh oh!
There was an error while loading. Please reload this page.
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.
❌ Unable to add follow-up after multiple attempts. The agent may be experiencing issues.
Please try again later or Open in Web to view the status.
Learn more about Cursor Agents
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.
@cursor fix
Uh oh!
There was an error while loading. Please reload this page.
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.
❌ Unable to add follow-up after multiple attempts. The agent may be experiencing issues.
Please try again later or Open in Web to view the status.
Learn more about Cursor Agents