Skip to content

fix: show error/warning toasts for device import failures (#1391)#1506

Open
ggfevans wants to merge 3 commits intomainfrom
fix/1391-import-feedback
Open

fix: show error/warning toasts for device import failures (#1391)#1506
ggfevans wants to merge 3 commits intomainfrom
fix/1391-import-feedback

Conversation

@ggfevans
Copy link
Copy Markdown
Collaborator

@ggfevans ggfevans commented Mar 23, 2026

User description

Summary

  • When ALL imported devices fail validation, show red error toast ("Import failed: No valid devices found in file") instead of misleading green success toast
  • When some devices are skipped during import, use yellow warning toast instead of green success
  • Share URL decode failures already had proper error toasts (no changes needed)

Files Changed

  • src/lib/utils/import.ts: Return error when all devices fail validation
  • src/lib/components/DialogOrchestrator.svelte: Use warning toast type when skipped > 0

Test Plan

  • All 1959 unit tests pass
  • Lint clean
  • CodeRabbit local review: no findings
  • Manual: import file with all valid devices → green success toast
  • Manual: import file with some invalid devices → yellow warning toast
  • Manual: import file with all invalid devices → red error toast
  • Manual: import bad JSON file → red error toast (pre-existing)

Closes #1391

🤖 Generated with Claude Code


CodeAnt-AI Description

Show clear import results when some or all devices are rejected

What Changed

  • Imports with no valid devices now fail with an error instead of showing a success message
  • Imports that skip some devices now show a warning, while fully successful imports still show success
  • The import message now tells users how many devices were added and how many were skipped

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:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

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:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

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.

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
Copy link
Copy Markdown
Contributor

codeant-ai bot commented Mar 23, 2026

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 ·
Reddit ·
LinkedIn

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 23, 2026

📝 Walkthrough

Walkthrough

Updated 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

Cohort / File(s) Summary
Import Feedback UI
src/lib/components/DialogOrchestrator.svelte
Use toast severity "warning" when result.skipped > 0; otherwise keep "success".
Device Library Validation
src/lib/utils/import.ts
After validating devices, return { devices: [], skipped, error: "No valid devices found in file" } when no devices remain (devices.length === 0) and some were skipped.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

size:S

Poem

A rabbit hops through files at night, 🐇
Counts the skips by lantern light,
When none survive the careful test,
It calls the error—no more rest,
And hums a toast to warn the rest.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR partially addresses issue #1391. It implements warning toasts for partial imports and error toasts for all-invalid devices, but does not implement error toasts for corrupt file imports or share URL decode failures mentioned in the acceptance criteria. Implement error handling in share.ts for URL decode failures and ensure corrupt JSON file imports also return error messages with proper error toast messaging.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding error/warning toasts for device import failures, which matches the primary objective of improving user feedback on import outcomes.
Description check ✅ Passed The description is well-structured and related to the changeset. It explains the rationale (misleading toasts), the solutions (error/warning toasts), the files changed, and includes a comprehensive test plan.
Out of Scope Changes check ✅ Passed The changes are narrowly focused on device import toast notifications. The two modified files (import.ts and DialogOrchestrator.svelte) directly support the stated objectives with no extraneous modifications.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/1391-import-feedback

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.

@codeant-ai codeant-ai bot added the size:XS This PR changes 0-9 lines, ignoring generated files label Mar 23, 2026
@codeant-ai
Copy link
Copy Markdown
Contributor

codeant-ai bot commented Mar 23, 2026

Sequence Diagram

This 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
Loading

Generated by CodeAnt AI

@codeant-ai
Copy link
Copy Markdown
Contributor

codeant-ai bot commented Mar 23, 2026

CodeAnt AI finished reviewing your PR.

ggfevans and others added 2 commits March 22, 2026 22:23
Co-authored-by: codeant-ai[bot] <151821869+codeant-ai[bot]@users.noreply.github.com>
Copy link
Copy Markdown
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: 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

📥 Commits

Reviewing files that changed from the base of the PR and between 2605583 and 7193ef4.

📒 Files selected for processing (1)
  • src/lib/utils/import.ts

Comment on lines +182 to +184
if (devices.length === 0) {
return { devices: [], skipped, error: "No valid devices found in file" };
}
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.

⚠️ Potential issue | 🟡 Minor

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.

Suggested change
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS This PR changes 0-9 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: Import/load failures should show user feedback instead of empty rack

1 participant