Skip to content

fix: handle URL construction error when switching to Visual Editor#35004

Merged
crazywoola merged 2 commits intolanggenius:mainfrom
samrusani:fix/json-schema-to-visual-editor-url-error
Apr 13, 2026
Merged

fix: handle URL construction error when switching to Visual Editor#35004
crazywoola merged 2 commits intolanggenius:mainfrom
samrusani:fix/json-schema-to-visual-editor-url-error

Conversation

@samrusani
Copy link
Copy Markdown
Contributor

@samrusani samrusani commented Apr 12, 2026

Summary

The jsonschema library's Validator.validate() internally calls new URL() for URI resolution of schema $id references, which can throw "Failed to construct 'URL': Invalid URL" in browser environments. This uncaught error propagated up to handleTabChange, where it was caught as a parse error — blocking the switch from JSON Schema to Visual Editor.

Added a try-catch in draft07Validator (web/utils/validators.ts) to handle this gracefully, returning empty validation errors on failure since structural schema validation is already covered by preValidateSchema.

Fixes #34841

Screenshots

N/A — the fix restores expected behavior (tab switching works without errors).

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran make lint and make type-check (backend) and cd web && pnpm exec vp staged (frontend) to appease the lint gods

From Claude Code

@samrusani samrusani requested a review from iamjoel as a code owner April 12, 2026 15:59
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Apr 12, 2026
@github-actions github-actions Bot added the web This relates to changes on the web. label Apr 12, 2026
crazywoola
crazywoola previously approved these changes Apr 13, 2026
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Apr 13, 2026
Sami Rusani and others added 2 commits April 13, 2026 12:38
The jsonschema library may throw "Failed to construct 'URL': Invalid URL"
in browser environments when resolving schema $id URIs internally. This
error was uncaught in draft07Validator, causing it to propagate up and
block the tab switch from JSON Schema to Visual Editor.

Catch the error gracefully and return empty validation errors, since
structural schema validation is already handled by preValidateSchema.

Closes langgenius#34841

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@samrusani samrusani force-pushed the fix/json-schema-to-visual-editor-url-error branch from 777e78d to a1c5140 Compare April 13, 2026 10:38
@crazywoola crazywoola added this pull request to the merge queue Apr 13, 2026
Merged via the queue into langgenius:main with commit 25a33a4 Apr 13, 2026
28 checks passed
HanqingZ pushed a commit to HanqingZ/dify that referenced this pull request Apr 23, 2026
…anggenius#35004)

Co-authored-by: Sami Rusani <sr@samirusani>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:S This PR changes 10-29 lines, ignoring generated files. web This relates to changes on the web.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can't change Visual Editor to JSON Schema

2 participants