Skip to content

fix: guard .trim() calls on potentially undefined workspaceDir - #24875

Merged
steipete merged 1 commit into
openclaw:mainfrom
omair445:fix/workspace-trim-guard-v2
Feb 24, 2026
Merged

steipete merged 1 commit into
openclaw:mainfrom
omair445:fix/workspace-trim-guard-v2

Conversation

@omair445

@omair445 omair445 commented Feb 23, 2026 •

Copy link
Copy Markdown
Contributor

Problem

resolvePluginSkillDirs types workspaceDir as string but callers can pass undefined, causing a TypeError: Cannot read properties of undefined (reading \x27trim\x27) crash.

Fix

  • Changed workspaceDir param type from string to string | undefined
  • Added nullish coalescing: (params.workspaceDir ?? "").trim()

This is a one-line type fix + one-line runtime guard. The existing early return on empty string handles the rest.

Supersedes #12956.

Greptile Summary

Updated resolvePluginSkillDirs to handle undefined workspaceDir parameter, preventing runtime crash when callers pass undefined values. Changed parameter type from string to string | undefined and added nullish coalescing operator to safely handle undefined before calling .trim().

The fix correctly addresses the TypeError by:

  • Making the type signature honest about accepting undefined
  • Using (params.workspaceDir ?? "") to convert undefined to empty string before trimming
  • Relying on existing empty-string check to return early

This is a minimal, defensive fix that prevents crashes without changing behavior for valid inputs.

Confidence Score: 5/5

  • This PR is safe to merge with no risk
  • The fix is minimal (2 lines), type-safe, and defensive. It prevents a clear runtime crash without introducing side effects. The nullish coalescing pattern is idiomatic TypeScript, and the existing empty-string check provides the safety net. No behavior changes for valid inputs.
  • No files require special attention

Last reviewed commit: f848180

Change workspaceDir param type from string to string | undefined in
resolvePluginSkillDirs and use nullish coalescing before .trim() to
prevent TypeError when workspaceDir is undefined.

@kevinWangSheng kevinWangSheng left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review Summary

This is a minimal, well-scoped fix for a real crash bug.

What it fixes

  • resolvePluginSkillDirs typed workspaceDir as string but callers could pass undefined, causing TypeError: Cannot read properties of undefined (reading 'trim')

Implementation quality

  • ✅ Type signature now honestly reflects reality: string | undefined
  • ✅ Defensive nullish coalescing: (params.workspaceDir ?? "").trim()
  • ✅ No behavior change for valid inputs
  • ✅ All CI checks pass (build, test, lint, Windows)

Security impact

None - this is a defensive bug fix.

Recommendation: Ready to merge

@steipete steipete left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed via /landpr flow. Diff scoped and checks looked good.

@steipete
steipete merged commit 177f167 into openclaw:main Feb 24, 2026
29 checks passed
plgs2005 pushed a commit to plgs2005/openclaw that referenced this pull request Feb 24, 2026
…law#24875)

Change workspaceDir param type from string to string | undefined in
resolvePluginSkillDirs and use nullish coalescing before .trim() to
prevent TypeError when workspaceDir is undefined.
margulans pushed a commit to margulans/Neiron-AI-assistant that referenced this pull request Feb 25, 2026
…law#24875)

Change workspaceDir param type from string to string | undefined in
resolvePluginSkillDirs and use nullish coalescing before .trim() to
prevent TypeError when workspaceDir is undefined.
kevinWangSheng pushed a commit to kevinWangSheng/openclaw that referenced this pull request Feb 26, 2026
…law#24875)

Change workspaceDir param type from string to string | undefined in
resolvePluginSkillDirs and use nullish coalescing before .trim() to
prevent TypeError when workspaceDir is undefined.
kevinWangSheng pushed a commit to kevinWangSheng/openclaw that referenced this pull request Feb 26, 2026
…law#24875)

Change workspaceDir param type from string to string | undefined in
resolvePluginSkillDirs and use nullish coalescing before .trim() to
prevent TypeError when workspaceDir is undefined.
@arjunaskykok arjunaskykok mentioned this pull request Feb 26, 2026
2 tasks done
mylukin pushed a commit to mylukin/openclaw that referenced this pull request Feb 26, 2026
…law#24875)

Change workspaceDir param type from string to string | undefined in
resolvePluginSkillDirs and use nullish coalescing before .trim() to
prevent TypeError when workspaceDir is undefined.
desertstackdev pushed a commit to desertstackdev/openclaw that referenced this pull request Feb 28, 2026
…law#24875)

Change workspaceDir param type from string to string | undefined in
resolvePluginSkillDirs and use nullish coalescing before .trim() to
prevent TypeError when workspaceDir is undefined.
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
…law#24875)

Change workspaceDir param type from string to string | undefined in
resolvePluginSkillDirs and use nullish coalescing before .trim() to
prevent TypeError when workspaceDir is undefined.
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
…law#24875)

Change workspaceDir param type from string to string | undefined in
resolvePluginSkillDirs and use nullish coalescing before .trim() to
prevent TypeError when workspaceDir is undefined.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
…law#24875)

Change workspaceDir param type from string to string | undefined in
resolvePluginSkillDirs and use nullish coalescing before .trim() to
prevent TypeError when workspaceDir is undefined.
lhfer pushed a commit to lhfer/openclaw that referenced this pull request Oct 11, 2026
…law#24875)

Change workspaceDir param type from string to string | undefined in
resolvePluginSkillDirs and use nullish coalescing before .trim() to
prevent TypeError when workspaceDir is undefined.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants