Skip to content

Handle errors when generating connectors#2402

Merged
ChinthakaJ98 merged 1 commit into
wso2:release/mi-4.1.2from
ChinthakaJ98:mi-fix-30
Jul 3, 2026
Merged

Handle errors when generating connectors#2402
ChinthakaJ98 merged 1 commit into
wso2:release/mi-4.1.2from
ChinthakaJ98:mi-fix-30

Conversation

@ChinthakaJ98

@ChinthakaJ98 ChinthakaJ98 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

$subject

Summary by CodeRabbit

  • New Features

    • Importing an API spec now returns a clear success/failure result with an optional error message.
  • Bug Fixes

    • Improved import handling so failures are detected immediately instead of continuing the workflow.
    • Added better error handling when no valid file is selected or an import throws an exception.
    • Import screens now stop loading correctly and show failed-import state when needed.

@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR changes importOpenAPISpec across the MI RPC stack to return a structured ImportOpenAPISpecResponse (with isSuccess and optional errorMessage) instead of void. The manager implementation now returns this response, and consuming UI components check isSuccess to handle import failures explicitly.

Changes

ImportOpenAPISpec structured response

Layer / File(s) Summary
Response type and RPC contract updates
workspaces/mi/mi-core/src/rpc-types/mi-visualizer/types.ts, .../index.ts, .../rpc-type.ts
Adds ImportOpenAPISpecResponse interface (isSuccess, optional errorMessage) and updates MIVisualizerAPI.importOpenAPISpec and the RPC type declaration to return it instead of void.
RPC manager implementation
workspaces/mi/mi-extension/src/rpc-managers/mi-visualizer/rpc-manager.ts
Updates MiVisualizerRpcManager.importOpenAPISpec to return { isSuccess: true } on success, or { isSuccess: false, errorMessage } on failure/invalid file path.
RPC client return type update
workspaces/mi/mi-rpc-client/src/rpc-clients/mi-visualizer/rpc-client.ts
Updates MiVisualizerRpcClient.importOpenAPISpec signature to return Promise<ImportOpenAPISpecResponse>.
UI import flow failure handling
workspaces/mi/mi-visualizer/src/views/Forms/ConnectionForm/ImportConnectionFromOpenAPI.tsx, .../ImportConnectionFromProto.tsx
Both import flows now check result?.isSuccess, set isFailedImport and stop importing on failure (including in catch blocks), returning early instead of proceeding.

Estimated code review effort: 2 (Simple) | ~15 minutes

Sequence Diagram(s)

sequenceDiagram
  participant UIComponent as ImportConnectionForm
  participant RpcClient as MiVisualizerRpcClient
  participant RpcManager as MiVisualizerRpcManager

  UIComponent->>RpcClient: importOpenAPISpec(params)
  RpcClient->>RpcManager: sendRequest(importOpenAPISpec)
  RpcManager-->>RpcClient: ImportOpenAPISpecResponse
  RpcClient-->>UIComponent: result
  alt result.isSuccess is false
    UIComponent->>UIComponent: setIsFailedImport(true)
    UIComponent->>UIComponent: setIsImporting(false)
  else success
    UIComponent->>UIComponent: waitForEvent / onImportSuccess
  end
Loading

Related issues: None specified.

Related PRs: None specified.

Suggested labels: None specified.

Suggested reviewers: None specified.

🐰 A hop, a skip, a response defined,
No more void left unrefined,
Success or failure, now made clear,
The import flow has naught to fear.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is only a placeholder and omits all required template sections. Replace the placeholder with the full template sections: Purpose, Goals, Approach, tests, security checks, documentation, and the other required items.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main change: connector generation/import now returns and handles explicit errors.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
workspaces/mi/mi-extension/src/rpc-managers/mi-visualizer/rpc-manager.ts (1)

923-943: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Wrap the connector copy in error handling.

copy(...) can throw on filesystem/permission/path errors, which makes importOpenAPISpec() reject instead of returning { isSuccess: false, errorMessage }. That breaks the method’s error-handling contract in the success path.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@workspaces/mi/mi-extension/src/rpc-managers/mi-visualizer/rpc-manager.ts`
around lines 923 - 943, The success path in importOpenAPISpec is missing error
handling around the connector file copy, so filesystem or permission failures
can escape as rejections. Wrap the copy(...) call in a try/catch inside
importOpenAPISpec, and on failure return { isSuccess: false, errorMessage }
while showing the error via vscode.window.showErrorMessage, keeping the same
error-handling contract used for langClient.generateConnector.
🧹 Nitpick comments (2)
workspaces/mi/mi-visualizer/src/views/Forms/ConnectionForm/ImportConnectionFromOpenAPI.tsx (2)

68-90: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Backend errorMessage is discarded in the UI.

result.errorMessage (and the error thrown in the catch block) is never surfaced; the UI always renders a generic "Error importing connector. Please try again..." message (Line 130) even though the response now carries a specific reason.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@workspaces/mi/mi-visualizer/src/views/Forms/ConnectionForm/ImportConnectionFromOpenAPI.tsx`
around lines 68 - 90, The OpenAPI import flow in importWithOpenAPI drops
backend-specific failure details, so the UI only shows a generic error. Update
the ImportConnectionFromOpenAPI component to capture and store
result.errorMessage from importOpenAPISpec and also use the caught error in the
catch block, then pass that message into the existing error rendering path
instead of always showing the default text. Keep the success path unchanged and
make sure the failure state in setIsFailedImport is triggered with the specific
reason from the RPC response or thrown exception.

68-90: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚖️ Poor tradeoff

Duplicated import-flow logic with ImportConnectionFromProto.tsx.

The importWithOpenAPI/importWithProto implementations (state reset, RPC call, early-return-on-failure, catch handling, waitForEvent) are now nearly identical across both files. Consider extracting a shared hook (e.g., useImportConnector) to avoid maintaining two copies of this logic.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@workspaces/mi/mi-visualizer/src/views/Forms/ConnectionForm/ImportConnectionFromOpenAPI.tsx`
around lines 68 - 90, The import flow in importWithOpenAPI is duplicating the
same state/reset, RPC call, early-return failure handling, catch logic, and
waitForEvent orchestration that already exists in ImportConnectionFromProto.tsx.
Extract the shared behavior into a reusable hook such as useImportConnector, and
have both importWithOpenAPI and importWithProto delegate to it while keeping
only the OpenAPI/Proto-specific inputs (like the RPC method and file path).
Preserve the existing success/failure state updates and onImportSuccess callback
behavior in the shared implementation.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@workspaces/mi/mi-extension/src/rpc-managers/mi-visualizer/rpc-manager.ts`:
- Around line 923-943: The success path in importOpenAPISpec is missing error
handling around the connector file copy, so filesystem or permission failures
can escape as rejections. Wrap the copy(...) call in a try/catch inside
importOpenAPISpec, and on failure return { isSuccess: false, errorMessage }
while showing the error via vscode.window.showErrorMessage, keeping the same
error-handling contract used for langClient.generateConnector.

---

Nitpick comments:
In
`@workspaces/mi/mi-visualizer/src/views/Forms/ConnectionForm/ImportConnectionFromOpenAPI.tsx`:
- Around line 68-90: The OpenAPI import flow in importWithOpenAPI drops
backend-specific failure details, so the UI only shows a generic error. Update
the ImportConnectionFromOpenAPI component to capture and store
result.errorMessage from importOpenAPISpec and also use the caught error in the
catch block, then pass that message into the existing error rendering path
instead of always showing the default text. Keep the success path unchanged and
make sure the failure state in setIsFailedImport is triggered with the specific
reason from the RPC response or thrown exception.
- Around line 68-90: The import flow in importWithOpenAPI is duplicating the
same state/reset, RPC call, early-return failure handling, catch logic, and
waitForEvent orchestration that already exists in ImportConnectionFromProto.tsx.
Extract the shared behavior into a reusable hook such as useImportConnector, and
have both importWithOpenAPI and importWithProto delegate to it while keeping
only the OpenAPI/Proto-specific inputs (like the RPC method and file path).
Preserve the existing success/failure state updates and onImportSuccess callback
behavior in the shared implementation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ce9ef616-6eeb-448f-8265-e4253f366831

📥 Commits

Reviewing files that changed from the base of the PR and between d223431 and 677a7b0.

📒 Files selected for processing (7)
  • workspaces/mi/mi-core/src/rpc-types/mi-visualizer/index.ts
  • workspaces/mi/mi-core/src/rpc-types/mi-visualizer/rpc-type.ts
  • workspaces/mi/mi-core/src/rpc-types/mi-visualizer/types.ts
  • workspaces/mi/mi-extension/src/rpc-managers/mi-visualizer/rpc-manager.ts
  • workspaces/mi/mi-rpc-client/src/rpc-clients/mi-visualizer/rpc-client.ts
  • workspaces/mi/mi-visualizer/src/views/Forms/ConnectionForm/ImportConnectionFromOpenAPI.tsx
  • workspaces/mi/mi-visualizer/src/views/Forms/ConnectionForm/ImportConnectionFromProto.tsx

@ChinthakaJ98 ChinthakaJ98 merged commit 69990f4 into wso2:release/mi-4.1.2 Jul 3, 2026
11 of 12 checks passed
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