Skip to content

Conversation

@fayching
Copy link
Contributor

@fayching fayching commented Oct 23, 2025

页面报错parseFunction error: {},原因是parseFunction函数传入的rawCode是"''",mock中的无用数据导致的

微信图片_20251022144259_89_10

English | 简体中文

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • Built its own designer, fully self-validated

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

Background and solution

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • Chores
    • Updated mock data for npm extension configuration with enhanced metadata and detailed property specifications.
    • Removed obsolete extension entries from mock data files.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 23, 2025

Walkthrough

Updates mock data files related to npm extension handling. Replaces npm extension in appinfo.json with expanded configuration, removes npm extension from app-center extension list, and removes npm utility from schema definitions.

Changes

Cohort / File(s) Summary
NPM extension configuration update
mockServer/src/assets/json/appinfo.json
Replaces npm extension object (id 146) with expanded configuration including version, subName, main, and detailed content properties with component metadata and configuration
NPM extension removal
mockServer/src/mock/get/app-center/apps/extension/list.json, mockServer/src/mock/get/app-center/v1/apps/schema/1.json
Removes npm extension entries (id 146 from extension list, npm utility from schema utils array)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify consistency: confirm that the removal of npm entries from list.json and schema/1.json aligns with the updated configuration in appinfo.json
  • Validate the new npm object structure in appinfo.json has all required properties and correct types

Poem

🐰 A bunny hops through mock data with glee,
Npm entries refined, now more clean and free,
Updated configs bloom with detailed delight,
Test data polished, everything just right! ✨

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly describes the bug being fixed: parseFunction error caused by empty string input. It matches the primary changes shown in the summary—removal of problematic mock data containing empty JSFunction values.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2105da0 and fd0958e.

📒 Files selected for processing (3)
  • mockServer/src/assets/json/appinfo.json (0 hunks)
  • mockServer/src/mock/get/app-center/apps/extension/list.json (0 hunks)
  • mockServer/src/mock/get/app-center/v1/apps/schema/1.json (0 hunks)
💤 Files with no reviewable changes (3)
  • mockServer/src/mock/get/app-center/apps/extension/list.json
  • mockServer/src/assets/json/appinfo.json
  • mockServer/src/mock/get/app-center/v1/apps/schema/1.json

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.

@github-actions github-actions bot added the bug Something isn't working label Oct 23, 2025
Copy link
Contributor

@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)
packages/utils/src/utils/index.ts (1)

50-50: Consider improving error logging for better debugging.

JSON.stringify(error) typically returns "{}" for Error objects because their properties are non-enumerable, which explains the unhelpful error message mentioned in the PR description. While your defensive checks should prevent most errors from reaching this point, consider using more informative error logging.

Apply this diff to improve error logging:

-    console.error(`parseFunction error: ${JSON.stringify(error)}`)
+    console.error('parseFunction error:', error?.message || error)

Or for more detail:

-    console.error(`parseFunction error: ${JSON.stringify(error)}`)
+    console.error(`parseFunction error: ${error?.stack || error?.message || String(error)}`)
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c27e843 and ddc4299.

📒 Files selected for processing (4)
  • mockServer/src/assets/json/appinfo.json (0 hunks)
  • mockServer/src/mock/get/app-center/apps/extension/list.json (0 hunks)
  • mockServer/src/mock/get/app-center/v1/apps/schema/1.json (0 hunks)
  • packages/utils/src/utils/index.ts (1 hunks)
💤 Files with no reviewable changes (3)
  • mockServer/src/mock/get/app-center/apps/extension/list.json
  • mockServer/src/mock/get/app-center/v1/apps/schema/1.json
  • mockServer/src/assets/json/appinfo.json
🔇 Additional comments (2)
packages/utils/src/utils/index.ts (2)

44-44: Good defensive check that fixes the root cause.

The early return correctly handles the case described in the PR where rawCode === "''" (a string literal containing two single quotes) would evaluate to an empty string when passed to the Function constructor, which would then fail when .bind() is called on the non-function result.

Note: The !rawCode check also catches all falsy values (0, false, null, undefined, empty string), which is appropriate for a code string parser.


46-47: Excellent defensive programming to prevent runtime errors.

The type check prevents calling .bind() on non-function results, which was the underlying cause of the error when rawCode evaluated to a string or other non-function value. This robustly handles cases where dynamic code evaluation produces unexpected types.

@fayching fayching changed the title fix:fix parseFunction error: {} fix:parseFunction error: failed to handle empty string input "''" Oct 23, 2025
@fayching fayching force-pushed the fayching/fix-parseFunction-error branch from ddc4299 to 2105da0 Compare October 30, 2025 06:43
@fayching fayching force-pushed the fayching/fix-parseFunction-error branch from 2105da0 to fd0958e Compare November 4, 2025 05:55
@chilingling chilingling merged commit 79cbf42 into opentiny:develop Nov 6, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants