Skip to content

Conversation

dcog989
Copy link
Contributor

@dcog989 dcog989 commented Sep 22, 2025

Fix crash when opening urls with non-existent local file in public api functions

@github-actions github-actions bot added this to the 2.1.0 milestone Sep 22, 2025

This comment has been minimized.

Copy link

gitstream-cm bot commented Sep 22, 2025

Be a legend 🏆 by adding a before and after screenshot of the changes you made, especially if they are around UI/UX.

This comment has been minimized.

@coderabbitai coderabbitai bot added the bug Something isn't working label Sep 22, 2025
Copy link
Member

@Jack251970 Jack251970 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for your contribution!👍

Copy link

@check-spelling-bot Report

🔴 Please review

See the 📂 files view, the 📜action log, or 📝 job summary for details.

❌ Errors and Warnings Count
❌ forbidden-pattern 2
⚠️ non-alpha-in-dictionary 2

See ❌ Event descriptions for more information.

Forbidden patterns 🙅 (1)

In order to address this, you could change the content to not match the forbidden patterns (comments before forbidden patterns may help explain why they're forbidden), add patterns for acceptable instances, or adjust the forbidden patterns themselves.

These forbidden patterns matched content:

Pattern

\b[Nn]o[nt][- ]existent\b
If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

@Jack251970 Jack251970 changed the title Crash when opening non-existent local file Fix crash when opening urls with non-existent local file Sep 22, 2025
Copy link

gitstream-cm bot commented Sep 22, 2025

🥷 Code experts: Jack251970, onesounds

Jack251970, onesounds have most 👩‍💻 activity in the files.
Jack251970, onesounds have most 🧠 knowledge in the files.

See details

Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs

Activity based on git-commit:

Jack251970 onesounds
SEP
AUG
JUL
JUN
MAY
APR 50 additions & 4 deletions

Knowledge based on git-blame:
Jack251970: 20%

Flow.Launcher/Languages/en.xaml

Activity based on git-commit:

Jack251970 onesounds
SEP 10 additions & 5 deletions
AUG 4 additions & 0 deletions
JUL 48 additions & 13 deletions
JUN 21 additions & 0 deletions 7 additions & 6 deletions
MAY 33 additions & 4 deletions 15 additions & 2 deletions
APR 22 additions & 21 deletions 45 additions & 23 deletions

Knowledge based on git-blame:
onesounds: 36%
Jack251970: 22%

Flow.Launcher/PublicAPIInstance.cs

Activity based on git-commit:

Jack251970 onesounds
SEP
AUG 30 additions & 23 deletions
JUL 22 additions & 6 deletions
JUN 54 additions & 22 deletions
MAY 124 additions & 131 deletions 190 additions & 74 deletions
APR 165 additions & 61 deletions

Knowledge based on git-blame:
Jack251970: 56%
onesounds: 7%

✨ Comment /gs review for LinearB AI review. Learn how to automate it here.

Copy link
Contributor

coderabbitai bot commented Sep 22, 2025

📝 Walkthrough

Walkthrough

Adds a new localized string key for file-not-found and a helper to check file-or-directory existence; updates PublicAPIInstance.OpenUri to pre-check existence for file URIs, show a localized error if missing, and wrap non-browser Process.Start in try/catch with logging and user-visible error.

Changes

Cohort / File(s) Summary
Localization: add error string
Flow.Launcher/Languages/en.xaml
Adds fileNotFoundError = "File or directory not found: {0}" to English resources.
Public API: OpenUri error handling
Flow.Launcher/PublicAPIInstance.cs
OpenUri now pre-validates file URIs and returns with localized error if missing; non-browser Process.Start wrapped in try/catch to log and show error. Removed a SuppressMessage attribute from RestartApp.
File utilities: existence helper
Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs
Adds public static bool FileOrLocationExists(this string path) that returns true if file or directory exists.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant API as PublicAPIInstance.OpenUri
  participant FS as FileSystem (File/Directory)
  participant Proc as Process.Start
  participant UI as ShowMsgError
  participant Log as Logger

  User->>API: OpenUri(uri)
  alt uri points to file system path
    API->>FS: FileOrLocationExists(path)?
    alt not exists
      API-->>UI: Show "fileNotFoundError" (localized)
      note right of API: return early
    else exists
      API->>Proc: Start(path) [non-browser]
      alt throws
        API->>Log: Log exception
        API-->>UI: Show error message
      end
    end
  else other URI (browser)
    API->>Proc: Start(uri) [browser]
    alt throws
      API->>Log: Log exception
      API-->>UI: Show error message
    end
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • jjw24
  • onesounds

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The PR title "Fix crash when opening urls with non-existent local file" accurately and concisely summarizes the primary change (preventing crashes when opening non-existent local file URIs) and is directly related to the changes in the diff.
Description Check ✅ Passed The PR description "Fix crash when opening urls with non-existent local file in public api functions" is directly related to the changeset (OpenUri pre-validation, error handling, and related string additions) and therefore meets the lenient acceptance criteria.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


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.

Copy link
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: 0

🧹 Nitpick comments (2)
Flow.Launcher/PublicAPIInstance.cs (2)

415-420: Pre-check fixes the crash; add log and minor tidy.

Log the miss to aid diagnostics and avoid re-evaluating uri.LocalPath twice.

-            if (uri.IsFile && !File.Exists(uri.LocalPath) && !Directory.Exists(uri.LocalPath))
-            {
-                ShowMsgError(GetTranslation("errorTitle"), string.Format(GetTranslation("fileNotFoundError"), uri.LocalPath));
-                return;
-            }
+            if (uri.IsFile)
+            {
+                var localPath = uri.LocalPath;
+                if (!File.Exists(localPath) && !Directory.Exists(localPath))
+                {
+                    LogWarn(ClassName, $"OpenUri path not found: {localPath}");
+                    ShowMsgError(GetTranslation("errorTitle"),
+                        string.Format(GetTranslation("fileNotFoundError"), localPath));
+                    return;
+                }
+            }

450-463: Use LocalPath for file URIs; optionally specialize error UX.

Using AbsoluteUri for file: targets can mis-handle percent‑encoding; prefer LocalPath. Optional: catch Win32Exception 1155 (“no association”) and show a friendly, localized message.

Minimal, safe tweak:

-                    Process.Start(new ProcessStartInfo()
-                    {
-                        FileName = uri.AbsoluteUri,
-                        UseShellExecute = true
-                    })?.Dispose();
+                    var psi = new ProcessStartInfo
+                    {
+                        FileName = uri.IsFile ? uri.LocalPath : uri.AbsoluteUri,
+                        UseShellExecute = true
+                    };
+                    Process.Start(psi)?.Dispose();

Optional (requires new locale keys, e.g., fileOpenError and fileNoAssociationError):

-                catch (Exception e)
-                {
-                    LogException(ClassName, $"Failed to open: {uri.AbsoluteUri}", e);
-                    ShowMsgError(GetTranslation("errorTitle"), e.Message);
-                }
+                catch (Win32Exception ex) when (ex.NativeErrorCode == 1155) // no association
+                {
+                    LogWarn(ClassName, $"No association to open: {uri}");
+                    ShowMsgError(GetTranslation("errorTitle"), GetTranslation("fileNoAssociationError"));
+                }
+                catch (Exception e)
+                {
+                    LogException(ClassName, $"Failed to open: {uri}", e);
+                    ShowMsgError(GetTranslation("errorTitle"),
+                        string.Format(GetTranslation("fileOpenError"), e.Message));
+                }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7de420e and 71b8144.

📒 Files selected for processing (2)
  • Flow.Launcher/Languages/en.xaml (1 hunks)
  • Flow.Launcher/PublicAPIInstance.cs (3 hunks)
🧰 Additional context used
🧠 Learnings (3)
📚 Learning: 2025-07-20T07:28:28.092Z
Learnt from: Jack251970
PR: Flow-Launcher/Flow.Launcher#3850
File: Flow.Launcher.Core/Resource/Internationalization.cs:0-0
Timestamp: 2025-07-20T07:28:28.092Z
Learning: In Flow Launcher's Internationalization class, when the Flow Launcher language directory or default language file is missing, the only viable approach is to log an error and return early - there are no fallback mechanisms or alternative recovery strategies available due to architectural constraints.

Applied to files:

  • Flow.Launcher/Languages/en.xaml
📚 Learning: 2025-09-05T11:56:27.267Z
Learnt from: Jack251970
PR: Flow-Launcher/Flow.Launcher#3593
File: Flow.Launcher/HotkeyControlDialog.xaml:6-6
Timestamp: 2025-09-05T11:56:27.267Z
Learning: In Flow.Launcher's migration to iNKORE.UI.WPF.Modern UI framework, dialog resource keys like PopuBGColor, PopupButtonAreaBGColor, PopupButtonAreaBorderColor, and PopupTextColor are provided by the iNKORE.UI.WPF.Modern framework itself, not defined locally in the codebase theme files.

Applied to files:

  • Flow.Launcher/Languages/en.xaml
📚 Learning: 2025-07-06T12:21:37.947Z
Learnt from: Jack251970
PR: Flow-Launcher/Flow.Launcher#3572
File: Flow.Launcher/App.xaml.cs:214-216
Timestamp: 2025-07-06T12:21:37.947Z
Learning: In Flow Launcher, the UpdatePluginManifestAsync method in PluginsManifest.cs already has comprehensive internal try-catch handling that logs exceptions and returns false on failure rather than throwing, making external try-catch wrappers unnecessary.

Applied to files:

  • Flow.Launcher/PublicAPIInstance.cs
🧬 Code graph analysis (1)
Flow.Launcher/PublicAPIInstance.cs (4)
Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs (3)
  • ShowMsgError (85-85)
  • GetTranslation (171-171)
  • LogException (311-311)
Flow.Launcher.Core/Plugin/JsonRPCV2Models/JsonRPCPublicAPI.cs (2)
  • ShowMsgError (62-65)
  • GetTranslation (97-100)
Flow.Launcher.Core/Resource/Internationalization.cs (1)
  • GetTranslation (348-360)
Flow.Launcher.Infrastructure/Logger/Log.cs (1)
  • Exception (93-103)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: gitStream.cm
  • GitHub Check: build
🔇 Additional comments (2)
Flow.Launcher/PublicAPIInstance.cs (1)

1-1: No review needed for BOM/using change.

Flow.Launcher/Languages/en.xaml (1)

593-593: Resolved — fileNotFoundError present in all locale files

All Flow.Launcher/Languages/*.xaml contain x:Key="fileNotFoundError"; no action required.

Copy link
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: 0

🧹 Nitpick comments (1)
Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs (1)

178-178: Consider refactoring to use the new helper method.

Line 178 currently uses LocationExists(fileOrFolderPath) || FileExists(fileOrFolderPath), which is exactly what the new FileOrLocationExists method does. This would be a good opportunity to use the new helper method for consistency.

Apply this diff to use the new helper method:

-                if (LocationExists(fileOrFolderPath) || FileExists(fileOrFolderPath))
+                if (fileOrFolderPath.FileOrLocationExists())
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 71b8144 and 763fee0.

📒 Files selected for processing (2)
  • Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs (1 hunks)
  • Flow.Launcher/PublicAPIInstance.cs (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • Flow.Launcher/PublicAPIInstance.cs
🧰 Additional context used
🪛 GitHub Actions: Check Spelling
Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs

[warning] Spell check warning: 'temppath' is not a recognized word.


[warning] Spell check warning: 'temppath' is not a recognized word.


[warning] Spell check warning: 'temppath' is not a recognized word.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: build
🔇 Additional comments (1)
Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs (1)

153-161: LGTM! Clean helper method implementation.

The new FileOrLocationExists method provides a convenient way to check for both file and directory existence in a single call. The implementation correctly delegates to the existing LocationExists and FileExists methods, maintaining consistency with the existing codebase patterns.

@Jack251970 Jack251970 merged commit 1e8819a into Flow-Launcher:dev Sep 22, 2025
8 checks passed
@dcog989 dcog989 deleted the 404-local-file-crash branch September 22, 2025 14:49
TBM13 pushed a commit to TBM13/Flow.Launcher that referenced this pull request Sep 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants