[PR #5997] [CLOSED] Fix JSON parsing errors #5456

Closed
opened 2026-03-17 02:53:56 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/hoppscotch/hoppscotch/pull/5997
Author: @tembo[bot]
Created: 3/16/2026
Status: Closed

Base: refactor/workspacesHead: tembo/refactor-workspace-abstractions


📝 Commits (2)

  • cdf371b fix(new-workspace): add JSON parse error handling in teams provider and clean test provider code
  • 8e33a5c fix(teams): add safe JSON parsing for environment variables and log errors

📊 Changes

2 files changed (+91 additions, -27 deletions)

View changed files

📝 packages/hoppscotch-common/src/services/new-workspace/providers/teams.workspace.ts (+89 -23)
📝 packages/hoppscotch-common/src/services/new-workspace/providers/test.workspace.ts (+2 -4)

📄 Description

Summary

Prevents crashes in the Teams workspace provider by safely parsing backend JSON for collections, requests, and environments. Malformed payloads are logged and skipped/defaulted instead of throwing.

What's changed

  • Added try/catch around JSON.parse(collection.data) for collection properties in teams.workspace.ts
  • Changed request parsing to flatMap + guarded JSON.parse(request.request) so malformed requests are skipped
  • Guarded remaining JSON.parse(environment.variables) sites (create/duplicate/update/import + environments view) and defaulted variables to [] on parse failure
  • Improved console error message wording ("request data" vs "response")
  • Cleaned up test workspace provider (removed unused timestamp/computed name; removed unnecessary provider cast)

Notes to reviewers

This makes the UI resilient to malformed JSON coming from the backend by ensuring parse errors don't bubble into runtime crashes. Parse failures are logged to console for debugging.


Want tembo to make any changes? Add a review or comment with @tembo and i'll get back to work!

View on Tembo View Agent Settings


Summary by cubic

Add safe JSON parsing across the Teams workspace provider to prevent crashes from malformed backend JSON. Guards are added for collection properties, requests, and environment variables; invalid data is skipped and errors are logged. Minor cleanup in the test provider.

  • Bug Fixes

    • Wrap JSON.parse for collection properties, request payloads, and team environment variables; log parse failures.
    • Use flatMap to skip malformed requests while preserving order; default env vars to [] on failure.
  • Refactors

    • Remove unused timestamp and computed name; use "Workspace A".
    • Drop unnecessary type assertion in registerWorkspaceProvider.

Written for commit 8e33a5cd92. Summary will update on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/hoppscotch/hoppscotch/pull/5997 **Author:** [@tembo[bot]](https://github.com/apps/tembo) **Created:** 3/16/2026 **Status:** ❌ Closed **Base:** `refactor/workspaces` ← **Head:** `tembo/refactor-workspace-abstractions` --- ### 📝 Commits (2) - [`cdf371b`](https://github.com/hoppscotch/hoppscotch/commit/cdf371b9d2cc044a5370358aeef6dba1d30b830b) fix(new-workspace): add JSON parse error handling in teams provider and clean test provider code - [`8e33a5c`](https://github.com/hoppscotch/hoppscotch/commit/8e33a5cd92961ce6a39e5c7a98cb9165421a11f6) fix(teams): add safe JSON parsing for environment variables and log errors ### 📊 Changes **2 files changed** (+91 additions, -27 deletions) <details> <summary>View changed files</summary> 📝 `packages/hoppscotch-common/src/services/new-workspace/providers/teams.workspace.ts` (+89 -23) 📝 `packages/hoppscotch-common/src/services/new-workspace/providers/test.workspace.ts` (+2 -4) </details> ### 📄 Description ## Summary Prevents crashes in the Teams workspace provider by safely parsing backend JSON for collections, requests, and environments. Malformed payloads are logged and skipped/defaulted instead of throwing. ### What's changed - Added `try/catch` around `JSON.parse(collection.data)` for collection properties in `teams.workspace.ts` - Changed request parsing to `flatMap` + guarded `JSON.parse(request.request)` so malformed requests are skipped - Guarded remaining `JSON.parse(environment.variables)` sites (create/duplicate/update/import + environments view) and defaulted variables to `[]` on parse failure - Improved console error message wording ("request data" vs "response") - Cleaned up test workspace provider (removed unused timestamp/computed name; removed unnecessary provider cast) ### Notes to reviewers This makes the UI resilient to malformed JSON coming from the backend by ensuring parse errors don't bubble into runtime crashes. Parse failures are logged to console for debugging. <br /> > Want tembo to make any changes? Add a review or comment with `@tembo` and i'll get back to work! <a href="https://app.tembo.io/tasks/a1005083-0baa-4373-b65e-7e8b073b1bcc"><picture><source media="(prefers-color-scheme: dark)" srcset="https://internal.tembo.io/static/view/tembo-dark.png?v=2"><source media="(prefers-color-scheme: light)" srcset="https://internal.tembo.io/static/view/tembo-light.png?v=2"><img alt="View on Tembo" src="https://internal.tembo.io/static/view/tembo-light.png?v=2" width="134" height="28"></picture></a> <a href="https://app.tembo.io/settings/models"><picture><source media="(prefers-color-scheme: dark)" srcset="https://internal.tembo.io/public/agent-button/codex:gpt-5.2?theme=dark&v=11"><source media="(prefers-color-scheme: light)" srcset="https://internal.tembo.io/public/agent-button/codex:gpt-5.2?theme=light&v=11"><img alt="View Agent Settings" src="https://internal.tembo.io/public/agent-button/codex:gpt-5.2?theme=light&v=11" height="28"></picture></a> <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Add safe JSON parsing across the Teams workspace provider to prevent crashes from malformed backend JSON. Guards are added for collection properties, requests, and environment variables; invalid data is skipped and errors are logged. Minor cleanup in the test provider. - **Bug Fixes** - Wrap `JSON.parse` for collection properties, request payloads, and team environment variables; log parse failures. - Use `flatMap` to skip malformed requests while preserving order; default env vars to `[]` on failure. - **Refactors** - Remove unused `timestamp` and computed name; use "Workspace A". - Drop unnecessary type assertion in `registerWorkspaceProvider`. <sup>Written for commit 8e33a5cd92961ce6a39e5c7a98cb9165421a11f6. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-17 02:53:56 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hoppscotch#5456
No description provided.