Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Programming exercises: Improve error handling when the diff report cannot be generated #10034

Merged
merged 11 commits into from
Dec 22, 2024

Conversation

krusche
Copy link
Member

@krusche krusche commented Dec 16, 2024

Checklist

General

Client

  • Important: I implemented the changes with a very good performance, prevented too many (unnecessary) REST calls and made sure the UI is responsive, even with large data (e.g. using paging).
  • I strictly followed the principle of data economy for all client-server REST calls.
  • I strictly followed the client coding and design guidelines.
  • I added multiple integration tests (Jest) related to the features (with a high test coverage), while following the test guidelines.
  • I translated all newly inserted strings into English and German.

Changes affecting Programming Exercises

  • High priority: I tested all changes and their related features with all corresponding user types on a test server configured with the integrated lifecycle setup (LocalVC and LocalCI).

Motivation and Context

A recent JGit issue caused the ProgrammingExerciseDetailComponent to fail rendering its sections. See #10029.
Any internal server error while fetching the diff reports would cause the component to crash.
While the JGit issue has been mitigated, the component should be more robust to server failures.

Description

catchError() is added to the RxJS pipeline to catch any errors produced by getDiffReport() and continue with the pipeline.
The diff report section is hidden in case of errors.

Steps for Testing

Prerequisites:

  • 1 Instructor

The server should work correctly. Test that the normal case works correctly.

  1. Create a programming exercise
  2. Verify that the details page has no missing sections

Testserver States

Note

These badges show the state of the test servers.
Green = Currently available, Red = Currently locked
Click on the badges to get to the test servers.







Review Progress

Code Review

  • Code Review 1
  • Code Review 2

Manual Tests

  • Test 1
  • Test 2

Test Coverage

Client

Class/File Line Coverage Confirmation (assert/expect)
programming-exercise-detail.component.ts 86.22%

Summary by CodeRabbit

Release Notes

  • New Features

    • Added localized error messages for diff report generation in both English and German.
  • Bug Fixes

    • Improved error handling for diff report retrieval, including user notifications for errors.
  • Documentation

    • Updated method signatures and added a new method for managing detail section updates.
  • Tests

    • Enhanced test coverage for error handling scenarios related to diff report retrieval.

@github-actions github-actions bot added the client Pull requests that update TypeScript code. (Added Automatically!) label Dec 16, 2024
@github-actions github-actions bot added the tests label Dec 20, 2024
@magaupp magaupp marked this pull request as ready for review December 20, 2024 22:25
@magaupp magaupp requested a review from a team as a code owner December 20, 2024 22:25
@magaupp magaupp temporarily deployed to artemis-test2.artemis.cit.tum.de December 20, 2024 22:27 — with GitHub Actions Inactive
Copy link

coderabbitai bot commented Dec 20, 2024

Walkthrough

This pull request introduces enhancements to the ProgrammingExerciseDetailComponent in the Angular application, focusing on error handling and code structure. Key modifications include updating the RxJS import to include catchError, refactoring the loadGitDiffReport method, and simplifying the processGitDiffReport method. A new method, updateDetailSections, has been added to manage UI updates effectively. Additionally, English and German translation files have been updated to include new error messages for diff report generation failures, along with corresponding test suite enhancements to verify the new error handling.

Changes

File Change Summary
src/main/webapp/app/exercises/programming/manage/programming-exercise-detail.component.ts - Updated RxJS import to include catchError
- Refactored loadGitDiffReport method
- Simplified processGitDiffReport method
- Added updateDetailSections method
src/main/webapp/i18n/de/programmingExercise.json Added German error message for diff report generation failure
src/main/webapp/i18n/en/programmingExercise.json Added English error message for diff report generation failure
src/test/javascript/spec/component/programming-exercise/programming-exercise-detail.component.spec.ts Updated import to include HttpErrorResponse
Added test case for error handling in diff report retrieval

Possibly related PRs

Suggested labels

ready for review, bugfix, small, code quality

Suggested reviewers

  • SimonEntholzer
  • florian-glombik
  • az108
  • JohannesWt
  • krusche

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8892b04 and 2e2ea18.

📒 Files selected for processing (2)
  • src/main/webapp/app/exercises/programming/manage/programming-exercise-detail.component.ts (5 hunks)
  • src/test/javascript/spec/component/programming-exercise/programming-exercise-detail.component.spec.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/test/javascript/spec/component/programming-exercise/programming-exercise-detail.component.spec.ts
  • src/main/webapp/app/exercises/programming/manage/programming-exercise-detail.component.ts

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • 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. (Beta)
  • @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 or @coderabbitai title anywhere in the PR title to generate the title automatically.

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 (3)
src/test/javascript/spec/component/programming-exercise/programming-exercise-detail.component.spec.ts (1)

224-232: Consider enhancing the error handling test coverage.

While the test case correctly verifies basic error handling, consider adding assertions to:

  1. Verify the specific error message being displayed
  2. Ensure that diff report UI elements are not shown when an error occurs
 it('should create detail sections after getDiffReport error', () => {
     const errorSpy = jest.spyOn(alertService, 'error');
     gitDiffReportStub.mockReturnValue(throwError(() => new HttpErrorResponse({ status: 500 })));

     comp.ngOnInit();

     expect(errorSpy).toHaveBeenCalledOnce();
+    expect(errorSpy).toHaveBeenCalledWith('artemisApp.programmingExercise.diffReportError');
     expect(comp.exerciseDetailSections).toBeDefined();
+    expect(comp.addedLineCount).toBeUndefined();
+    expect(comp.removedLineCount).toBeUndefined();
 });
src/main/webapp/app/exercises/programming/manage/programming-exercise-detail.component.ts (2)

Line range hint 799-813: Consider extracting the line count calculation logic.

The line count calculation could be extracted into a separate private method for better maintainability and reusability.

 private processGitDiffReport(gitDiffReport: ProgrammingExerciseGitDiffReport | undefined): void {
     const isGitDiffReportUpdated =
         gitDiffReport &&
         (this.programmingExercise.gitDiffReport?.templateRepositoryCommitHash !== gitDiffReport.templateRepositoryCommitHash ||
             this.programmingExercise.gitDiffReport?.solutionRepositoryCommitHash !== gitDiffReport.solutionRepositoryCommitHash);
     if (isGitDiffReportUpdated) {
         this.programmingExercise.gitDiffReport = gitDiffReport;
         gitDiffReport.programmingExercise = this.programmingExercise;
-
-        const calculateLineCount = (entries: { lineCount?: number; previousLineCount?: number }[] = [], key: 'lineCount' | 'previousLineCount') =>
-            entries.map((entry) => entry[key] ?? 0).reduce((sum, count) => sum + count, 0);
-
-        this.addedLineCount = calculateLineCount(gitDiffReport.entries, 'lineCount');
-        this.removedLineCount = calculateLineCount(gitDiffReport.entries, 'previousLineCount');
+        this.addedLineCount = this.calculateLineCount(gitDiffReport.entries, 'lineCount');
+        this.removedLineCount = this.calculateLineCount(gitDiffReport.entries, 'previousLineCount');
     }
 }
+
+private calculateLineCount(entries: { lineCount?: number; previousLineCount?: number }[] = [], key: 'lineCount' | 'previousLineCount'): number {
+    return entries.map((entry) => entry[key] ?? 0).reduce((sum, count) => sum + count, 0);
+}

828-834: Consider adding debounce to prevent rapid UI updates.

The method could benefit from debouncing to prevent performance issues when called frequently in succession.

+private readonly DEBOUNCE_TIME = 300; // ms
+private updateDetailSectionsSubject = new Subject<void>();
+
+private initializeUpdateDetailSections(): void {
+    this.updateDetailSectionsSubject
+        .pipe(
+            debounceTime(this.DEBOUNCE_TIME),
+            takeUntil(this.destroy$)
+        )
+        .subscribe(() => {
+            this.exerciseDetailSections = this.getExerciseDetails();
+        });
+}
+
 /**
  * <strong>BE CAREFUL WHEN CALLING THIS METHOD!</strong><br>
  * Warnings of {@link getExerciseDetails} apply.
  */
 private updateDetailSections(): void {
-    this.exerciseDetailSections = this.getExerciseDetails();
+    this.updateDetailSectionsSubject.next();
 }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c00d635 and 8892b04.

📒 Files selected for processing (4)
  • src/main/webapp/app/exercises/programming/manage/programming-exercise-detail.component.ts (6 hunks)
  • src/main/webapp/i18n/de/programmingExercise.json (1 hunks)
  • src/main/webapp/i18n/en/programmingExercise.json (1 hunks)
  • src/test/javascript/spec/component/programming-exercise/programming-exercise-detail.component.spec.ts (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/main/webapp/i18n/de/programmingExercise.json
🧰 Additional context used
📓 Path-based instructions (2)
src/test/javascript/spec/component/programming-exercise/programming-exercise-detail.component.spec.ts (1)

Pattern src/test/javascript/spec/**/*.ts: jest: true; mock: NgMocks; bad_practices: avoid_full_module_import; perf_improvements: mock_irrelevant_deps; service_testing: mock_http_for_logic; no_schema: avoid_NO_ERRORS_SCHEMA; expectation_specificity: true; solutions: {boolean: toBeTrue/False, reference: toBe, existence: toBeNull/NotNull, undefined: toBeUndefined, class_obj: toContainEntries/toEqual, spy_calls: {not_called: not.toHaveBeenCalled, once: toHaveBeenCalledOnce, with_value: toHaveBeenCalledWith|toHaveBeenCalledExactlyOnceWith}}

src/main/webapp/app/exercises/programming/manage/programming-exercise-detail.component.ts (1)

Pattern src/main/webapp/**/*.ts: angular_style:https://angular.io/guide/styleguide;methods_in_html:false;lazy_loading:true;code_reuse:true;tests:meaningful;types:PascalCase;enums:PascalCase;funcs:camelCase;props:camelCase;no_priv_prefix:true;strings:single_quotes;localize:true;btns:functionality;links:navigation;icons_text:newline;labels:associate;code_style:arrow_funcs,curly_braces,open_braces_same_line,indent_4;memory_leak_prevention:true;routes:naming_schema;chart_framework:ngx-charts;responsive_layout:true

🔇 Additional comments (5)
src/test/javascript/spec/component/programming-exercise/programming-exercise-detail.component.spec.ts (1)

28-28: LGTM!

The addition of HttpErrorResponse import is appropriate for testing error handling scenarios.

src/main/webapp/app/exercises/programming/manage/programming-exercise-detail.component.ts (3)

60-60: LGTM!

The addition of catchError operator is appropriate for handling errors in RxJS streams.


468-478: LGTM!

Good defensive programming by checking both addedLineCount and removedLineCount before displaying the diff report. This prevents showing incomplete or invalid reports to users.


817-824: LGTM!

The error handling is well-implemented with appropriate user feedback through the alert service.

src/main/webapp/i18n/en/programmingExercise.json (1)

219-219: LGTM!

The error message is clear, concise, and follows the existing translation patterns.

coderabbitai[bot]
coderabbitai bot previously approved these changes Dec 20, 2024
@magaupp magaupp temporarily deployed to artemis-test2.artemis.cit.tum.de December 20, 2024 23:19 — with GitHub Actions Inactive
Copy link

@sawys777 sawys777 left a comment

Choose a reason for hiding this comment

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

Tested on TS3, every details were displayed correctly

@krusche krusche added this to the 7.8.0 milestone Dec 22, 2024
@krusche krusche merged commit f54177f into develop Dec 22, 2024
66 of 70 checks passed
@krusche krusche deleted the bugfix/diff-report-error-handling branch December 22, 2024 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client Pull requests that update TypeScript code. (Added Automatically!) ready for review tests
Projects
Status: Merged
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants