Skip to content

UFAL/File preview better logs#910

Merged
milanmajchrak merged 5 commits intodtq-devfrom
ufal/file-preview-better-logs
Apr 1, 2025
Merged

UFAL/File preview better logs#910
milanmajchrak merged 5 commits intodtq-devfrom
ufal/file-preview-better-logs

Conversation

@milanmajchrak
Copy link
Collaborator

@milanmajchrak milanmajchrak commented Apr 1, 2025

Phases MP MM MB MR JM Total
ETA 0 0 0 0 0 0
Developing 0 0 0 0 0 0
Review 0 0 0 0 0 0
Total - - - - - 0
ETA est. 0
ETA cust. - - - - - 0

Problem description

Catch every exception during generating the file preview and log info about the item and the exception.

Summary by CodeRabbit

  • Refactor
    • Improved error management across content preview and metadata services to ensure a more consistent and resilient experience when handling unexpected issues. These updates streamline exception handling by consolidating multiple specific exceptions into a single general exception type, contributing to greater overall stability for users.

@coderabbitai
Copy link

coderabbitai bot commented Apr 1, 2025

Walkthrough

This pull request simplifies exception handling across several modules. Method signatures in service implementations, interfaces, scripts, and repositories have been updated to throw a generic Exception instead of multiple specific exceptions. Corresponding try-catch blocks have been removed, allowing errors to propagate to the caller. The changes primarily affect preview content processing and metadata bitstream retrieval, streamlining the error management in these areas.

Changes

File(s) Change Summary
dspace-api/.../PreviewContentServiceImpl.java
dspace-api/.../service/PreviewContentService.java
Updated method signatures to throw a general Exception instead of specific ones (e.g., SQLException, IOException, etc.) and removed nested try-catch blocks handling exceptions during file preview content extraction.
dspace-api/.../scripts/FilePreview.java Simplified exception handling by replacing multiple catch blocks with a general exception catch and updating the generateItemFilePreviews method signature to throw a generic Exception.
dspace-server-webapp/.../MetadataBitstreamRestRepository.java Modified the findByHandle method signature to throw a single generic Exception rather than several specific exceptions.

Possibly related PRs

Poem

I hopped through lines of code so fine,
Replacing many errors with one neat sign.
No more catching every little fall,
I leaped through logic, handling them all.
With a twitch of my nose and a joyful bound,
I celebrate clean code all around!
🐰 Hop on, dear devs, and spread the cheer!


📜 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 0e1432c and accc573.

📒 Files selected for processing (2)
  • dspace-api/src/main/java/org/dspace/scripts/filepreview/FilePreview.java (2 hunks)
  • dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/MetadataBitstreamRestRepository.java (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • dspace-api/src/main/java/org/dspace/scripts/filepreview/FilePreview.java
  • dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/MetadataBitstreamRestRepository.java
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Run Integration Tests
  • GitHub Check: dspace-dependencies / docker-build (linux/amd64, ubuntu-latest, true)
  • GitHub Check: Run Unit Tests

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

Copy link

@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)
dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/MetadataBitstreamRestRepository.java (1)

70-71: Changed exception handling to use a generic Exception type.

The method signature has been modified to throw a generic Exception instead of specific exceptions (SQLException, ParserConfigurationException, IOException, SAXException, AuthorizeException, and ArchiveException). This simplifies the exception specification but reduces type safety by hiding expected failure cases from callers.

While this change aligns with the PR objective to better handle exceptions during file preview generation, consider maintaining specific exception types in public API methods for better caller awareness. Alternatively, document the potential exceptions that might be thrown in the method's JavaDoc.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7b3a1f3 and 0e1432c.

📒 Files selected for processing (4)
  • dspace-api/src/main/java/org/dspace/content/PreviewContentServiceImpl.java (4 hunks)
  • dspace-api/src/main/java/org/dspace/content/service/PreviewContentService.java (2 hunks)
  • dspace-api/src/main/java/org/dspace/scripts/filepreview/FilePreview.java (2 hunks)
  • dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/MetadataBitstreamRestRepository.java (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: dspace-dependencies / docker-build (linux/amd64, ubuntu-latest, true)
  • GitHub Check: Run Integration Tests
  • GitHub Check: Run Unit Tests
🔇 Additional comments (9)
dspace-api/src/main/java/org/dspace/scripts/filepreview/FilePreview.java (2)

102-105: Simplified exception catch block to handle all exceptions.

The catch block now handles the generic Exception type instead of multiple specific exceptions. This change is aligned with the PR objective to catch all exceptions during file preview generation.


117-117: Method signature updated to throw a generic Exception.

The method signature has been changed from declaring multiple specific exceptions to a single Exception type. This simplifies the method signature but reduces the clarity of what exceptions callers should expect.

dspace-api/src/main/java/org/dspace/content/service/PreviewContentService.java (2)

118-118: Interface method signature updated to throw a generic Exception.

The getFilePreviewContent method now throws a generic Exception instead of specific exceptions (SQLException, AuthorizeException, IOException). This change simplifies the interface but reduces type information for implementers and callers.


153-154: Interface method signature updated to throw a generic Exception.

The processInputStreamToFilePreview method now throws a generic Exception instead of specific exceptions (SQLException, IOException). This change aligns with the PR's goal of simplifying exception handling.

dspace-api/src/main/java/org/dspace/content/PreviewContentServiceImpl.java (5)

154-155: Method signature updated to throw a generic Exception.

The getFilePreviewContent method implementation now throws a generic Exception instead of specific exceptions, matching the interface change. Additionally, it appears the nested exception handling has been removed, allowing exceptions to propagate up the call stack.


163-163: Removed try-catch block for specific exception.

A try-catch block for IllegalStateException has been removed, allowing any exceptions from processInputStreamToFilePreview to propagate to the caller. This change streamlines the error handling flow.


191-192: Method signature updated to throw a generic Exception.

The processInputStreamToFilePreview method implementation now throws a generic Exception rather than specific exceptions, matching the interface change.


215-216: Removed try-catch blocks around file extraction.

Try-catch blocks have been removed around the calls to extractFile and FileTreeViewGenerator.parse, allowing any exceptions to propagate to the caller. This simplifies the control flow and ensures exceptions are logged at a higher level.


415-415: Method signature updated to throw a generic Exception.

The extractFile method now declares that it can throw Exception instead of handling exceptions internally. This change allows for better error propagation and more centralized error handling.

…dev/DSpace into ufal/file-preview-better-logs
@milanmajchrak milanmajchrak changed the title Ufal/File preview better logs UFAL/File preview better logs Apr 1, 2025
@milanmajchrak milanmajchrak merged commit 5ecfa18 into dtq-dev Apr 1, 2025
11 checks passed
kosarko added a commit to ufal/clarin-dspace that referenced this pull request Apr 10, 2025
Merging latest dataquest-dev/dspace:dtq-dev

This contains the following commits:

Run build action every 4h for every customer/ branch
UFAL/Do not use not-existing metadatafield `hasMetadata` in the submission-forms-cz (dataquest-dev#888)
UFAL/Created job to generate preview for every item or for a specific one (dataquest-dev#887)
UFAL/bitstream preview wrong file name according to it's mimetype (dataquest-dev#890)
Fixed typo in the error exception
The owning community was null. (dataquest-dev#891)
The `+` characted was wrongly encoded in the URL (dataquest-dev#893)
Set limit when splitting key/value using `=` (dataquest-dev#894)
Ufal/header value could have equals char (dataquest-dev#895)
UFAL/File preview - Added the method for extracting the file into try catch block (dataquest-dev#909)
UFAL/File preview better logs (dataquest-dev#910)
UFAL/File preview - Return empty list if an error has occured (dataquest-dev#915)
UFAL/Matomo fix tracking of the statistics (dataquest-dev#912)
UFAL/Matomo statistics - Use the bitstream name instead of the UUID in the tracking download url (dataquest-dev#917)
UFAL/Matomo bitstream tracker has error when bitstream name was null (dataquest-dev#918)
UFAL/Endpoints leaks private information (dataquest-dev#924)

UFAL/Fix parts identifiers resolution (dataquest-dev#913)
UFAL/Update `clarin-dspace.cfg` - handle.plugin.checknameauthority (dataquest-dev#897)

Creating Legal check (dataquest-dev#863)

import/comment-license-script (dataquest-dev#882)

UFAL/Renamed property dspace.url to dspace.ui.url (dataquest-dev#906)
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.

1 participant