fix: show error/warning toasts for device import failures (#1391)#1506
fix: show error/warning toasts for device import failures (#1391)#1506
Conversation
When all imported devices fail validation, show error toast instead of misleading "Imported 0 devices" success. When some devices are skipped, use warning toast type instead of success. Fixes #1391 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
CodeAnt AI is reviewing your PR. Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
📝 WalkthroughWalkthroughUpdated import flow: the UI shows a warning toast when device library import skips any devices; the import parser now returns an explicit error ("No valid devices found in file") when all devices fail validation instead of returning an empty device list. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
Sequence DiagramThis PR changes device import feedback so fully invalid imports now fail with an error toast, and partial imports show a warning toast instead of success. It prevents misleading success messages by basing toast type on validation outcomes. sequenceDiagram
participant User
participant Dialog
participant ImportParser
participant LayoutStore
participant Toast
User->>Dialog: Select and import device file
Dialog->>ImportParser: Parse and validate imported devices
alt No valid devices found
ImportParser-->>Dialog: Return error with skipped count
Dialog->>Toast: Show error import failed no valid devices
else At least one valid device
ImportParser-->>Dialog: Return valid devices and skipped count
Dialog->>LayoutStore: Add valid devices and mark dirty
alt Some devices skipped
Dialog->>Toast: Show warning imported with skipped
else No devices skipped
Dialog->>Toast: Show success imported devices
end
end
Generated by CodeAnt AI |
|
CodeAnt AI finished reviewing your PR. |
Co-authored-by: codeant-ai[bot] <151821869+codeant-ai[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/lib/utils/import.ts`:
- Around line 182-184: The current check in src/lib/utils/import.ts returns the
message "No valid devices found in file" whenever devices.length === 0 even if
skipped === 0; change the logic in the import handling (the block that inspects
devices and skipped) to only return the "No valid devices found in file" error
when devices.length === 0 AND skipped > 0, and otherwise return the appropriate
empty-import result (e.g., when skipped === 0 treat it as an empty payload/no
devices provided); update the conditional that uses devices and skipped to
reflect this distinction so callers can tell between an all-invalid import and
an empty input.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 38b6a858-e2bb-40e9-bb6e-7e5592e04cdf
📒 Files selected for processing (1)
src/lib/utils/import.ts
| if (devices.length === 0) { | ||
| return { devices: [], skipped, error: "No valid devices found in file" }; | ||
| } |
There was a problem hiding this comment.
Clarify empty-import behavior vs “all invalid” behavior.
Line 182 treats an empty file payload (devices: []) as "No valid devices found in file" even when skipped === 0. If the intended behavior is specifically “all provided devices failed validation,” gate this on skipped > 0.
Suggested adjustment
- if (devices.length === 0) {
+ if (devices.length === 0 && skipped > 0) {
return { devices: [], skipped, error: "No valid devices found in file" };
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if (devices.length === 0) { | |
| return { devices: [], skipped, error: "No valid devices found in file" }; | |
| } | |
| if (devices.length === 0 && skipped > 0) { | |
| return { devices: [], skipped, error: "No valid devices found in file" }; | |
| } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/lib/utils/import.ts` around lines 182 - 184, The current check in
src/lib/utils/import.ts returns the message "No valid devices found in file"
whenever devices.length === 0 even if skipped === 0; change the logic in the
import handling (the block that inspects devices and skipped) to only return the
"No valid devices found in file" error when devices.length === 0 AND skipped >
0, and otherwise return the appropriate empty-import result (e.g., when skipped
=== 0 treat it as an empty payload/no devices provided); update the conditional
that uses devices and skipped to reflect this distinction so callers can tell
between an all-invalid import and an empty input.
User description
Summary
Files Changed
src/lib/utils/import.ts: Return error when all devices fail validationsrc/lib/components/DialogOrchestrator.svelte: Use warning toast type when skipped > 0Test Plan
Closes #1391
🤖 Generated with Claude Code
CodeAnt-AI Description
Show clear import results when some or all devices are rejected
What Changed
Impact
✅ Clearer device import results✅ Fewer misleading success messages✅ Better feedback when imports contain invalid devices💡 Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.