Skip to content

fix: prevent crash on corrupted interface in edit dialog#710

Merged
torlando-tech merged 1 commit intomainfrom
fix/693-edit-dialog-crash-on-corrupted-interface
Mar 25, 2026
Merged

fix: prevent crash on corrupted interface in edit dialog#710
torlando-tech merged 1 commit intomainfrom
fix/693-edit-dialog-crash-on-corrupted-interface

Conversation

@torlando-tech
Copy link
Copy Markdown
Owner

Summary

  • Fixes error #693showEditDialog() was the only entityToConfig() caller without a try-catch
  • A corrupted type field in the Room database (e.g. invisible unicode characters) caused IllegalArgumentException to crash the app when the user tapped an interface to edit it
  • Now catches the exception and shows a user-visible error message instead of crashing

Test plan

  • All existing InterfaceManagementViewModel tests pass (121 tasks, BUILD SUCCESSFUL)
  • Manual: corrupt an interface entity's type field and verify tapping it shows an error toast instead of crashing

🤖 Generated with Claude Code

…interface

Fixes #693 — entityToConfig throws IllegalArgumentException for unknown
interface types, but showEditDialog was the only caller without a
try-catch. A corrupted type field in the database (e.g. invisible
unicode characters) would crash the app on tap. Now shows an error
message instead.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 24, 2026

Greptile Summary

This PR closes a crash bug (#693) by wrapping showEditDialog() in a try-catch, making it consistent with every other entityToConfig call site in the ViewModel. The fix is minimal, targeted, and follows the established error-handling pattern already used by saveInterface, deleteInterface, and other methods.

Key changes:

  • showEditDialog() now catches any Exception thrown by entityToConfigState() (e.g. IllegalArgumentException from a corrupted type field in Room DB)
  • On failure: logs the error via Log.e and surfaces a user-visible message via showError() — the dialog stays closed, no crash
  • On success: behaviour is identical to before

Confidence Score: 5/5

  • Safe to merge — single-function change with no behavioural impact on the happy path.
  • The change is a one-function, one-site addition of a try-catch that exactly mirrors the existing error-handling pattern used throughout the rest of the ViewModel. There is no change to the success path, no new state introduced, and the error path correctly leaves the dialog closed and config state untouched for the next operation. All existing tests pass.
  • No files require special attention.

Important Files Changed

Filename Overview
app/src/main/java/com/lxmf/messenger/viewmodel/InterfaceManagementViewModel.kt Adds try-catch to showEditDialog — the only entityToConfig call site that previously lacked error handling — matching the existing pattern used by saveInterface and deleteInterface.

Sequence Diagram

sequenceDiagram
    participant UI as UI / Composable
    participant VM as InterfaceManagementViewModel
    participant Repo as InterfaceRepository
    participant DB as Room DB

    UI->>VM: showEditDialog(interfaceEntity)

    alt Happy path (valid entity)
        VM->>Repo: entityToConfig(entity)
        Repo->>DB: lookup type field
        DB-->>Repo: valid type string
        Repo-->>VM: InterfaceConfig (typed)
        VM->>VM: _configState.value = entityToConfigState(...)
        VM->>VM: _state.value.copy(showAddDialog=true, editingInterface=entity)
        VM-->>UI: dialog opens
    else Corrupted entity (e.g. bad `type` field) — NEW behaviour
        VM->>Repo: entityToConfig(entity)
        Repo-->>VM: throws IllegalArgumentException
        VM->>VM: Log.e(TAG, ...)
        VM->>VM: showError("Failed to load interface: …")
        VM->>VM: _state.value.copy(errorMessage=…)
        VM-->>UI: error toast / snackbar shown, dialog stays closed
    end
Loading

Reviews (1): Last reviewed commit: "fix: catch exception in showEditDialog t..." | Re-trigger Greptile

@sentry
Copy link
Copy Markdown
Contributor

sentry bot commented Mar 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@torlando-tech torlando-tech merged commit c7e9d1e into main Mar 25, 2026
14 checks passed
@torlando-tech torlando-tech deleted the fix/693-edit-dialog-crash-on-corrupted-interface branch March 25, 2026 00:00
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.

error

1 participant