Skip to content

fix(ai-enhancer): guard ruleBasedDescription against empty words (crashes on PascalCase names)#1

Open
louisdurden wants to merge 1 commit into
amarnath3003:mainfrom
louisdurden:fix/rulebased-empty-word
Open

fix(ai-enhancer): guard ruleBasedDescription against empty words (crashes on PascalCase names)#1
louisdurden wants to merge 1 commit into
amarnath3003:mainfrom
louisdurden:fix/rulebased-empty-word

Conversation

@louisdurden

Copy link
Copy Markdown

Problem

analyze crashes during description generation on any codebase that exports PascalCase or all-caps identifiers:

TypeError: Cannot read properties of undefined (reading 'toUpperCase')
    at ruleBasedDescription (.../ai-enhancer/dist/index.js)
    at applyRuleBasedDescriptions
    at runAnalysis

The crash happens after the full tool surface is computed (backend actions, DB ops, workflows all succeed), so the whole analysis is lost at the last step.

Root cause

In packages/ai-enhancer/src/index.ts, ruleBasedDescription:

const words = name.replace(/([A-Z])/g, ' $1').toLowerCase().split(' ');

When name starts with an uppercase letter (e.g. GET, createPatient, useSoapSign), the regex prepends a leading space, so split(' ') produces a leading empty-string element. The final line then does w[0].toUpperCase() on '', and ''[0] is undefined.

Fix

Trim before splitting and drop empty tokens so words never contains an empty string:

const words = name.replace(/([A-Z])/g, ' $1').trim().toLowerCase().split(/\s+/).filter(Boolean);

Repro

Run analyze against any project with PascalCase exports (a Next.js App Router app reproduces it reliably — hundreds of route.ts / component exports). Before: crash. After: completes and emits descriptions normally.

PascalCase or all-caps tool names (e.g. "GET", "createPatient") begin
with an uppercase letter, so name.replace(/([A-Z])/g, ' $1') prepends a
leading space. .split(' ') then yields a leading '' element, and
words.map((w,i) => i===0 ? w[0].toUpperCase()... ) throws
"Cannot read properties of undefined (reading 'toUpperCase')".

Trim before splitting and filter empties so `words` never contains an
empty string. Reproduces on any codebase with PascalCase exports
(e.g. a Next.js App Router project), crashing `analyze` after the tool
surface has already been computed.
@vercel

vercel Bot commented Jun 12, 2026

Copy link
Copy Markdown

@louisdurden is attempting to deploy a commit to the Amarnath's projects Team on Vercel.

A member of the Team first needs to authorize it.

@amarnath3003 amarnath3003 self-assigned this Jun 12, 2026
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.

2 participants