Skip to content

Fix media download error handling and improve code organization#1248

Open
vl-ivanov wants to merge 4 commits into
photoview:masterfrom
vl-ivanov:fix-notification-layout-follow-up
Open

Fix media download error handling and improve code organization#1248
vl-ivanov wants to merge 4 commits into
photoview:masterfrom
vl-ivanov:fix-notification-layout-follow-up

Conversation

@vl-ivanov

@vl-ivanov vl-ivanov commented Jul 13, 2025

Copy link
Copy Markdown
Contributor
  • Removed unnecessary debug code from the tests
  • Added error handling
  • Fixed typo
  • Improve code organization

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling for downloads with invalid content length, now displaying a notification if a download fails due to zero or invalid content length.
  • Style

    • Corrected a typo in the type name for sidebar media download properties.
    • Cleaned up import order and removed unnecessary code/comments in test files.
  • Chores

    • Updated .gitignore to exclude specific test reports and directories from version control.
  • Tests

    • Added tests for download error handling scenarios to ensure proper notifications are shown when media download fails.

@coderabbitai

coderabbitai Bot commented Jul 13, 2025

Copy link
Copy Markdown

Walkthrough

The changes update the .gitignore file to exclude specific files and directories from version control, clean up formatting and remove unused code in a test file, and enhance error handling, notification behavior, and type definitions in a sidebar media download component. A new test suite was added to verify error handling in the download progress function. The downloadMediaShowProgress function was also exported for external use.

Changes

File(s) Change Summary
.gitignore Added ui/junit-report.xml and api/photoview to ignored paths.
ui/src/components/sidebar/MediaSidebar/MediaSidebar.test.tsx Removed a blank line and a commented-out debug statement from a test.
ui/src/components/sidebar/SidebarDownloadMedia.tsx Reordered imports, improved error handling for invalid content length, adjusted notification logic, fixed a type name typo (SidebarMediaDownladPropsSidebarMediaDownloadProps), and exported downloadMediaShowProgress.
ui/src/components/sidebar/SidebarDownloadMedia.test.tsx Added new test suite for downloadMediaShowProgress covering error handling for null reader and invalid content length scenarios.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SidebarMediaDownload
    participant NotificationSystem

    User->>SidebarMediaDownload: Initiate media download
    SidebarMediaDownload->>SidebarMediaDownload: Check content length and reader
    alt Content length or reader is nil or invalid
        SidebarMediaDownload->>NotificationSystem: Add negative notification ("Downloading media failed")
        SidebarMediaDownload-->>User: Return early, abort download
    else Valid content length and reader
        SidebarMediaDownload->>SidebarMediaDownload: Proceed with download, show progress notification
        SidebarMediaDownload->>NotificationSystem: Update notification on progress
        SidebarMediaDownload-->>User: Download completes successfully
    end
Loading

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5f63cde and 74734bc.

📒 Files selected for processing (1)
  • ui/src/components/sidebar/SidebarDownloadMedia.test.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • ui/src/components/sidebar/SidebarDownloadMedia.test.tsx
⏰ 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). (7)
  • GitHub Check: CodeQL (javascript)
  • GitHub Check: CodeQL (go)
  • GitHub Check: Build Docker Image (refs/pull/1248/merge)
  • GitHub Check: Test UI
  • GitHub Check: Test API (sqlite)
  • GitHub Check: Test API (mysql)
  • GitHub Check: Test API (postgres)
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 124b6d3 and a0924e7.

📒 Files selected for processing (3)
  • .gitignore (1 hunks)
  • ui/src/components/sidebar/MediaSidebar/MediaSidebar.test.tsx (0 hunks)
  • ui/src/components/sidebar/SidebarDownloadMedia.tsx (5 hunks)
💤 Files with no reviewable changes (1)
  • ui/src/components/sidebar/MediaSidebar/MediaSidebar.test.tsx
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: DanielOaks
PR: photoview/photoview#1016
File: ui/src/components/mapbox/mapboxHelperFunctions.tsx:44-57
Timestamp: 2025-04-13T05:39:39.494Z
Learning: For Photoview PRs, feature enhancements like improved error logging should be suggested as separate PRs rather than being included in dependency update PRs, which should focus on minimal necessary code changes.
Learnt from: googollee
PR: photoview/photoview#1228
File: dependencies/build_imagemagick.sh:0-0
Timestamp: 2025-06-27T13:17:26.027Z
Learning: In the photoview project, when doing rollbacks/reverts, googollee prefers to keep the revert clean and address any code quality issues in separate PRs rather than mixing fixes with the revert itself.
Learnt from: DanielOaks
PR: photoview/photoview#1016
File: ui/src/components/mapbox/mapboxHelperFunctions.tsx:101-115
Timestamp: 2025-04-13T05:38:45.180Z
Learning: Error handling improvements and code style changes should be addressed in dedicated PRs rather than bundled with dependency update PRs which should remain focused on minimal changes required for the updates.
Learnt from: kkovaletp
PR: photoview/photoview#1165
File: ui/package.json:62-62
Timestamp: 2025-01-27T19:55:21.158Z
Learning: Updating vite-plugin-pwa to match workbox v7 dependencies in the Photoview project is planned for a future PR and should not be included in the current PWA implementation changes.
Learnt from: kkovaletp
PR: photoview/photoview#1200
File: api/scanner/media_encoding/encode_photo.go:39-39
Timestamp: 2025-05-09T17:59:05.683Z
Learning: In PhotoView, when removing a feature like thumbnail preferences, it's important to clean up all related code including GraphQL schema definitions, resolvers, UI components, tests, and auto-generated TypeScript files. After removing GraphQL schema definitions, always regenerate TypeScript types with `npm run genSchemaTypes` to remove enum types and operation files that are no longer needed. Don't forget to check for references in global type definitions like `globalTypes.ts`.
Learnt from: kkovaletp
PR: photoview/photoview#1200
File: api/scanner/media_encoding/encode_photo.go:39-39
Timestamp: 2025-05-09T17:59:05.683Z
Learning: In PhotoView, when removing a feature like thumbnail preferences, all related code should be completely removed including GraphQL schema definitions, resolvers, UI components, tests, and generated TypeScript files. TypeScript definitions should be regenerated with `npm run genSchemaTypes` after removing GraphQL schema definitions to ensure all references are removed.
.gitignore (3)
Learnt from: kkovaletp
PR: photoview/photoview#1239
File: Dockerfile:23-29
Timestamp: 2025-07-05T19:01:23.736Z
Learning: In the Photoview project's UI package.json, build tools like Vite are placed in the `dependencies` section rather than `devDependencies`, allowing production builds to work correctly with `npm ci --omit=dev` while still having access to build tools during the Docker build stage.
Learnt from: kkovaletp
PR: photoview/photoview#1239
File: Dockerfile:23-29
Timestamp: 2025-07-05T19:01:23.736Z
Learning: In the Photoview project's UI package.json, build tools like Vite are placed in the `dependencies` section rather than `devDependencies`, allowing production builds to work correctly with `npm ci --omit=dev` while still having access to build tools during the Docker build stage.
Learnt from: kkovaletp
PR: photoview/photoview#1221
File: .github/workflows/build.yml:132-137
Timestamp: 2025-06-21T11:30:57.197Z
Learning: In the Photoview repository, cache scopes in GitHub Actions workflows are intentionally named consistently across different workflow files (build.yml and tests.yml) to enable cache reuse between workflows when dependency files match. The "test-ui" and "test-api" prefixes are used strategically for this cross-workflow cache optimization.
ui/src/components/sidebar/SidebarDownloadMedia.tsx (1)
Learnt from: kkovaletp
PR: photoview/photoview#965
File: ui/src/components/sidebar/SidebarDownloadMedia.tsx:58-58
Timestamp: 2025-02-07T18:49:05.058Z
Learning: In the Photoview frontend, message notifications can include an optional `onDismiss` callback property, which is primarily used for progress notifications to handle cancellation of ongoing operations.
🧬 Code Graph Analysis (1)
ui/src/components/sidebar/SidebarDownloadMedia.tsx (3)
ui/src/helpers/utils.ts (1)
  • isNil (38-40)
ui/src/components/messages/Messages.tsx (1)
  • MessageState (27-46)
ui/src/components/sidebar/MediaSidebar/MediaSidebar.tsx (1)
  • MediaSidebarMedia (242-270)
⏰ 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: CodeQL (go)
  • GitHub Check: CodeQL (javascript)
  • GitHub Check: Build Docker Image (refs/pull/1248/merge)
  • GitHub Check: Build Dependencies Image
  • GitHub Check: Test API (sqlite)
  • GitHub Check: Test API (mysql)
  • GitHub Check: Test API (postgres)
  • GitHub Check: Test UI
🔇 Additional comments (5)
.gitignore (1)

45-46: LGTM! Appropriate exclusions for build artifacts.

Adding test reports and build artifacts to .gitignore follows best practices for keeping generated files out of version control.

ui/src/components/sidebar/SidebarDownloadMedia.tsx (4)

14-16: LGTM! Clean import organization.

The import reordering and addition of the isNil utility are appropriate improvements to code organization.


77-77: LGTM! Simplified variable declaration.

Removing the unnecessary null initialization is a good cleanup since the variable gets assigned conditionally later.


183-185: LGTM! Cleaner return statement.

Directly returning the Blob instead of assigning to an intermediate variable improves code readability.


259-259: LGTM! Fixed the typo in type name.

Correcting SidebarMediaDownladProps to SidebarMediaDownloadProps fixes the spelling error and improves code consistency.

Also applies to: 263-263

Comment thread ui/src/components/sidebar/SidebarDownloadMedia.tsx Outdated
@codecov

codecov Bot commented Jul 13, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.23810% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 58.70%. Comparing base (124b6d3) to head (74734bc).
⚠️ Report is 102 commits behind head on master.

Files with missing lines Patch % Lines
ui/src/components/sidebar/SidebarDownloadMedia.tsx 95.23% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1248      +/-   ##
==========================================
+ Coverage   58.23%   58.70%   +0.46%     
==========================================
  Files         205      205              
  Lines       17957    17968      +11     
  Branches      564      580      +16     
==========================================
+ Hits        10458    10548      +90     
+ Misses       7114     7035      -79     
  Partials      385      385              
Flag Coverage Δ
api-mysql 39.52% <ø> (ø)
api-postgres 39.61% <ø> (+0.02%) ⬆️
api-sqlite 39.56% <ø> (ø)
ui 69.49% <95.23%> (+0.73%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 142555d and 5f63cde.

📒 Files selected for processing (2)
  • ui/src/components/sidebar/SidebarDownloadMedia.test.tsx (1 hunks)
  • ui/src/components/sidebar/SidebarDownloadMedia.tsx (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • ui/src/components/sidebar/SidebarDownloadMedia.tsx
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: DanielOaks
PR: photoview/photoview#1016
File: ui/src/components/mapbox/mapboxHelperFunctions.tsx:44-57
Timestamp: 2025-04-13T05:39:39.494Z
Learning: For Photoview PRs, feature enhancements like improved error logging should be suggested as separate PRs rather than being included in dependency update PRs, which should focus on minimal necessary code changes.
Learnt from: googollee
PR: photoview/photoview#1228
File: dependencies/build_imagemagick.sh:0-0
Timestamp: 2025-06-27T13:17:26.027Z
Learning: In the photoview project, when doing rollbacks/reverts, googollee prefers to keep the revert clean and address any code quality issues in separate PRs rather than mixing fixes with the revert itself.
Learnt from: DanielOaks
PR: photoview/photoview#1016
File: ui/src/components/mapbox/mapboxHelperFunctions.tsx:101-115
Timestamp: 2025-04-13T05:38:45.180Z
Learning: Error handling improvements and code style changes should be addressed in dedicated PRs rather than bundled with dependency update PRs which should remain focused on minimal changes required for the updates.
Learnt from: kkovaletp
PR: photoview/photoview#1165
File: ui/package.json:62-62
Timestamp: 2025-01-27T19:55:21.158Z
Learning: Updating vite-plugin-pwa to match workbox v7 dependencies in the Photoview project is planned for a future PR and should not be included in the current PWA implementation changes.
Learnt from: kkovaletp
PR: photoview/photoview#1200
File: api/scanner/media_encoding/encode_photo.go:39-39
Timestamp: 2025-05-09T17:59:05.683Z
Learning: In PhotoView, when removing a feature like thumbnail preferences, it's important to clean up all related code including GraphQL schema definitions, resolvers, UI components, tests, and auto-generated TypeScript files. After removing GraphQL schema definitions, always regenerate TypeScript types with `npm run genSchemaTypes` to remove enum types and operation files that are no longer needed. Don't forget to check for references in global type definitions like `globalTypes.ts`.
ui/src/components/sidebar/SidebarDownloadMedia.test.tsx (2)
Learnt from: kkovaletp
PR: photoview/photoview#965
File: ui/src/components/messages/MessageProgress.tsx:14-22
Timestamp: 2024-12-14T20:19:15.719Z
Learning: In the `MessageProgress` component (`ui/src/components/messages/MessageProgress.tsx`), avoid extracting constants (e.g., thresholds, colors) unless they are reused elsewhere to keep the code concise and maintainable.
Learnt from: kkovaletp
PR: photoview/photoview#965
File: ui/src/components/messages/Message.tsx:10-11
Timestamp: 2024-12-14T14:58:22.663Z
Learning: In `ui/src/components/messages/Message.tsx`, the `negative` and `positive` props in the `MessageProps` type are part of the contract and should be retained as-is.
🧬 Code Graph Analysis (1)
ui/src/components/sidebar/SidebarDownloadMedia.test.tsx (4)
ui/src/components/messages/Messages.tsx (1)
  • MessageState (27-46)
ui/src/components/sidebar/SidebarDownloadMedia.tsx (1)
  • downloadMediaShowProgress (306-306)
api/graphql/models/generated.go (1)
  • NotificationType (196-196)
ui/src/components/messages/SubscriptionsHook.ts (1)
  • Message (24-36)
⏰ 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: CodeQL (javascript)
  • GitHub Check: CodeQL (go)
  • GitHub Check: Build Docker Image (refs/pull/1248/merge)
  • GitHub Check: Test API (mysql)
  • GitHub Check: Test API (postgres)
  • GitHub Check: Test API (sqlite)
  • GitHub Check: Test UI
  • GitHub Check: Build Dependencies Image

Comment thread ui/src/components/sidebar/SidebarDownloadMedia.test.tsx
Comment thread ui/src/components/sidebar/SidebarDownloadMedia.test.tsx Outdated
Comment thread ui/src/components/sidebar/SidebarDownloadMedia.test.tsx Outdated
@vl-ivanov

Copy link
Copy Markdown
Contributor Author

@kkovaletp please, review :)

Comment thread .gitignore
yarn-error.log*
.eslintcache
ui/junit-report.xml
api/photoview

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.

What is the api/photoview and why should it be globally ignored?
If it is something for the local API server execution, it is better to move it under the already ignored folders:
/storage
/database
/tmp

Comment thread ui/src/components/sidebar/SidebarDownloadMedia.test.tsx
Comment on lines +52 to +62
// eslint-disable-next-line @typescript-eslint/unbound-method
expect(MessageState.add).toHaveBeenCalledWith(
expect.objectContaining({
type: NotificationType.Close,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
props: expect.objectContaining({
negative: true,
header: 'Downloading media failed',
}),
})
)

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.

Are these ESLint inline mutters the only way to implement this verification logic? As far as I know, in most cases when you need to mute a linter, there should be an exceptional need. If that is it - ok. I'm asking just to make sure)

Comment on lines +114 to +115
content: `The content length of the downloaded media is 0 bytes, which has no sense and usually
means that there is an unknown lower-level error.`,

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.

From this message, I see that you've checked my repo's implementation) I see that you've enhanced it by covering more negative cases and adding tests.
I have more messages defined there, but I guess that implementing them would require more complex changes...

@kkovaletp kkovaletp added bug Something isn't working UI Related to the frontend web ui written in Javascript javascript Pull requests that update Javascript code improvement Something, enhancing the product, but not a feature labels Aug 24, 2025
@github-project-automation github-project-automation Bot moved this to In progress in Roadmap Aug 24, 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 improvement Something, enhancing the product, but not a feature javascript Pull requests that update Javascript code UI Related to the frontend web ui written in Javascript

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

2 participants