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: Display error message for unexpected errors on exercise import #8463

Conversation

florian-glombik
Copy link
Contributor

@florian-glombik florian-glombik commented Apr 23, 2024

Checklist

General

Client

  • 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 added multiple screenshots/screencasts of my UI changes.

Motivation and Context

A missing error message confused instructors when importing programming exercises with the system in an unexpected state.
An instructor tried to import an exercise and nothing happened (meaning that there was an error in the network tab that was not displayed as an alert in the user interface).

The error occurs in ProgrammingExerciseExportImportResource.importProgrammingExercise, most likely related to a duplicated exercise short name that is not covered by ProgrammingExerciseRepository.validateCourseSettings.

de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException: Project already exists on the Version Control Server: exerciseTitle. Please choose a different title and short name!
        at de.tum.in.www1.artemis.service.programming.ProgrammingExerciseService.checkIfProjectExists(ProgrammingExerciseService.java:896)
        at de.tum.in.www1.artemis.service.programming.ProgrammingExerciseImportService.importProgrammingExercise(ProgrammingExerciseImportService.java:277)
        at de.tum.in.www1.artemis.web.rest.programming.ProgrammingExerciseExportImportResource.importProgrammingExercise(ProgrammingExerciseExportImportResource.java:217)

Description

Adjusting the client side of the programming exercise import display to display an alert for unexpected errors.

  • adjusting the alert.service that intercepts all errors to display an alert for errors where the "error" object is not set but the response is an error (using the header fields x-artemisapp-error and x-artemisapp-message for the alert, or throwing a generic error message if these are not defined)
  • adding tests for the new error handling logic
  • adding a translation that was missing on the client side
  • calling scrollToTopOfPage instead of duplicating the code

Steps for Testing

On the test server

  • Make sure that error alerts are not displayed twice (this can affect all areas of Artemis, since the adjusted alert.service intercepts all errors)
  • after creating a programming exercise successfully, the page should scroll to the top

Locally

I do not know how to test the fallback "unexpected error message" on the testserver

I am not sure how to get the system into a state leading to the issue described; I was able to reproduce the state by importing a programming exercise with a duplicate short name and disabling the duplicate check.

  1. Disable the duplicate check

    1. Open the ProgrammingExerciseExportImportResource class
    2. Comment out the line programmingExerciseRepository.validateCourseSettings(newExercise, course);
  2. Import a programming exercise with a duplicate short name

  3. An error message should be displayed as alert in the upper right corner

  4. Enable the duplicate check again and verify that only one alert is displayed

In my case the thrown error is POST http://localhost:9000/api/programming-exercises/import/1?recreateBuildPlans=false&updateTemplate=false 500 (Internal Server Error)

Testserver States

Note

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






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-update.component.ts 87.85%

Screenshots

Now

image

Before

image

Page just stays open, nothing happens

Summary by CodeRabbit

  • New Features

    • Enhanced error alert handling based on HTTP status codes in the application.
    • Improved user feedback with updated error messages and translation parameters.
  • Bug Fixes

    • Fixed error alert handling in programming exercise updates.
  • Tests

    • Added new test cases for alert handling in both programming exercise updates and general alert services.
  • Refactor

    • Refactored error handling logic for clearer and more efficient user notifications.
    • Replaced direct page scrolling with utility function for smoother user experience.

@florian-glombik florian-glombik self-assigned this Apr 23, 2024
@github-actions github-actions bot added the client Pull requests that update TypeScript code. (Added Automatically!) label Apr 23, 2024
@florian-glombik florian-glombik added this to the 7.0.2 milestone Apr 23, 2024
@florian-glombik florian-glombik changed the title Programming exercises: Displaying error message for unexpected errors on exercise import Programming exercises: Display error message for unexpected errors on exercise import Apr 23, 2024
@github-actions github-actions bot added the tests label Apr 23, 2024
@florian-glombik florian-glombik marked this pull request as ready for review April 23, 2024 18:30
@florian-glombik florian-glombik requested a review from a team as a code owner April 23, 2024 18:30
Copy link

coderabbitai bot commented Apr 23, 2024

Walkthrough

The changes across the files aim to enhance error handling and user feedback mechanisms in the programming exercise update component. These improvements include refining error messages, incorporating utility functions for page scrolling, and enhancing alert displays for better user guidance during error scenarios.

Changes

File Path Change Summary
.../programming-exercise-update.component.ts Added import for scrollToTopOfPage, updated error handling logic, and modified alert service usage.
.../programming-exercise-update.component.spec.ts Added a test case for handling alerts during an unknown error in the update process.
.../alert.service.ts Updated error alert handling based on HTTP response status codes for more detailed error messages.

Possibly related issues


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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[bot]
coderabbitai bot previously approved these changes Apr 23, 2024
Copy link
Contributor

@pzdr7 pzdr7 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 TS1.

Tried to import a programming exercise with a duplicate short name.


The response is 400 Bad Request with an appropriate alert visible. For some reason, the "unexpected error" is shown with text "OK". Can we do anything about that?

image

@florian-glombik
Copy link
Contributor Author

Thanks for testing @pzdr7 #8463 (review), the issue was that the alert.service intercepts all HTTP errors, which led to 2 alerts being displayed with the previous solution.

The new solution addresses the issue directly in the alert.service

Strohgelaender
Strohgelaender previously approved these changes Apr 26, 2024
Copy link
Contributor

@Strohgelaender Strohgelaender left a comment

Choose a reason for hiding this comment

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

code lgtm

sarpsahinalp
sarpsahinalp previously approved these changes Apr 26, 2024
Copy link
Contributor

@sarpsahinalp sarpsahinalp left a comment

Choose a reason for hiding this comment

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

Tested during testing session, lgtm

@florian-glombik florian-glombik requested a review from pzdr7 April 26, 2024 12:39
@florian-glombik florian-glombik modified the milestones: 7.0.2, 7.0.3 Apr 26, 2024
az108
az108 previously approved these changes Apr 26, 2024
Copy link
Contributor

@az108 az108 left a comment

Choose a reason for hiding this comment

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

Worked fine for me during the testing session!

egekurt123
egekurt123 previously approved these changes Apr 26, 2024
Copy link
Contributor

@egekurt123 egekurt123 left a comment

Choose a reason for hiding this comment

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

Local Behavior showcased during the testing session, TS Behavior tested manually on TS1 -> Both work as described

coolchock
coolchock previously approved these changes Apr 26, 2024
Copy link
Contributor

@coolchock coolchock left a comment

Choose a reason for hiding this comment

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

presented in testing session locally, works as expected

pzdr7
pzdr7 previously approved these changes Apr 26, 2024
Copy link
Contributor

@pzdr7 pzdr7 left a comment

Choose a reason for hiding this comment

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

Code looks good. Left one comment, but I'll leave it up to you.

…ix-error-handling-for-unexpected-errors

# Conflicts:
#	src/main/java/de/tum/in/www1/artemis/web/rest/programming/ProgrammingExerciseExportImportResource.java
@florian-glombik
Copy link
Contributor Author

The actual issue will be fixed in #8523. The content of this PR will be refined in which I will link here once it is created, addressing a refactoring of the server & client-side error handling.

@krusche krusche deleted the bugfix/programming-exercises/fix-error-handling-for-unexpected-errors branch September 29, 2024 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix client Pull requests that update TypeScript code. (Added Automatically!) component:Programming server Pull requests that update Java code. (Added Automatically!) tests
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

7 participants