Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 19, 2025

This PR addresses a crash issue where reportLink could be nil but was being force unwrapped, causing the app to crash when users attempted to report topics that don't have report functionality available.

Problem

The issue occurred in the feed detail parsing logic where:

  1. When V2EX pages don't contain a report link (empty rawReportUrl), the reportLink property remained nil
  2. Later, when users tried to report such topics, FeedDetailActions.swift would force unwrap state.model.reportLink!, causing a crash
  3. The UI didn't account for cases where reporting wasn't available

Solution

Model Layer (FeedDetailInfo.swift):

  • Added an else clause to initialize reportLink as an empty string when rawReportUrl is empty
  • This ensures reportLink is never nil, preventing force unwrap crashes

Action Layer (FeedDetailActions.swift):

  • Added a guard statement to safely check if reportLink exists and is not empty before proceeding
  • Provides user feedback ("无法举报此主题") when report functionality is unavailable
  • Gracefully handles the error case without crashing

UI Layer (FeedDetailPage.swift):

  • Added canReport logic to disable the report button when reportLink is empty
  • Improves user experience by preventing users from attempting impossible actions

Testing

Added a test case to verify that reportLink is properly initialized as an empty string rather than remaining nil.

This fix ensures the app handles V2EX topics that don't support reporting functionality without crashing, while maintaining full functionality for topics that do support reporting.

Fixes #4.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copy link
Contributor Author

Copilot AI commented Sep 19, 2025

@graycreate 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

Co-authored-by: graycreate <5203798+graycreate@users.noreply.github.com>
Copilot AI changed the title [WIP] Splash Screen Fix reportLink nil handling to prevent crashes when report functionality unavailable Sep 19, 2025
Copilot AI requested a review from graycreate September 19, 2025 12:00
Copilot finished work on behalf of graycreate September 19, 2025 12:00
@github-actions github-actions bot added size/S and removed size/S labels Sep 20, 2025
@github-actions
Copy link

Code Coverage Report ❌

Current coverage: 0%

@graycreate graycreate marked this pull request as ready for review September 20, 2025 05:19
Copilot AI review requested due to automatic review settings September 20, 2025 05:19
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a crash issue where reportLink could be nil but was being force unwrapped when users attempted to report topics that don't have report functionality available.

Key changes:

  • Prevents nil reportLink by initializing it as empty string when no report URL is found
  • Adds safety guards in report action to handle empty report links gracefully
  • Updates UI to disable report button when reporting is unavailable

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
V2er/State/DataFlow/Model/FeedDetailInfo.swift Ensures reportLink is initialized as empty string instead of remaining nil
V2er/State/DataFlow/Actions/FeedDetailActions.swift Adds guard to safely check report link before proceeding with report action
V2er/View/FeedDetail/FeedDetailPage.swift Adds logic to disable report button when report link is unavailable
V2erTests/V2erTests.swift Adds test case to verify proper handling of empty report links

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
13.5}
}
Copy link

Copilot AI Sep 20, 2025

Choose a reason for hiding this comment

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

The removed line contains invalid syntax 13.5} which would cause compilation errors. This appears to be a formatting issue in the diff rather than intentional code.

Copilot uses AI. Check for mistakes.
@github-actions
Copy link

Code Coverage Report ❌

Current coverage: 0%

@graycreate graycreate closed this Sep 23, 2025
@graycreate graycreate deleted the copilot/fix-4 branch September 23, 2025 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Splash Screen

2 participants