Skip to content

Commit

Permalink
[FIX] Fixes skip faulty warning being shown (#4564)
Browse files Browse the repository at this point in the history
**Description**

When the server takes too long to respond to a  `/parse` request, the front-end assumes that this must be because it is recompiling the program after finding errors, due to this code in `app.ts`

```
let errorsFoundTimeout = setTimeout(function () {
        error.showWarningSpinner();
        error.showWarning(ClientMessages['Execute_error'], ClientMessages['Errors_found']);
      }, 500)

let response = await postJsonWithAchievements('/parse', data);
clearTimeout(errorsFoundTimeout);
error.hide()
```
This essentially means: wait for 500 ms for response, if it answers before you don't execute the function and hides any possible errors. I changed that and now we only show the warning box if we find errors we skipped in the source map. This means that we are not relying on the response time of the server, and will reliably show the warning. 

I changed also the wording of the warning and now it says this: "You made a mistake! Don't worry, we still ran the program". However, @Felienne can you tell me if this is a good wording, I'm not sure this is clear enough.

**How to test**

Easiest way to reproduce is:

1. add a sleep to `/parse` endpoint
2. See that now even if the server takes long to respond the skip faulty error is not shown

Depends-On: #4560
  • Loading branch information
jpelay committed Sep 27, 2023
1 parent 15beb17 commit de5c1da
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 48 deletions.
2 changes: 1 addition & 1 deletion content/client-messages/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ CheckInternet: "Have a look if your Internet connection is working properly."
ServerError: "You wrote a program we weren't expecting. If you want to help, send us an email with the level and your program at [email protected]. In the meantime, try something a little different and take another look at the examples. Thanks!"
Program_too_long: "Your program takes too long to run."
Program_repair: "This could be the correct code, can you fix it?"
Errors_found: "You made a mistake! Don't worry, Hedy is trying to find the mistakes"
Errors_found: "You made a mistake! Don't worry, we still ran the program"
21 changes: 12 additions & 9 deletions static/js/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,15 +532,8 @@ export async function runit(level: number, lang: string, disabled_prompt: string
save_name: saveNameFromInput(),
};

let errorsFoundTimeout = setTimeout(function () {
error.showWarningSpinner();
error.showWarning(ClientMessages['Execute_error'], ClientMessages['Errors_found']);
}, 500)

let response = await postJsonWithAchievements('/parse', data);
clearTimeout(errorsFoundTimeout);
console.log('Response', response);
error.hide();

showAchievements(response.achievements, false, "");
if (adventure && response.save_info) {
Expand Down Expand Up @@ -820,6 +813,8 @@ window.onerror = function reportClientException(message, source, line_number, co
export function runPythonProgram(this: any, code: string, sourceMap: any, hasTurtle: boolean, hasPygame: boolean, hasSleep: boolean, hasWarnings: boolean, cb: () => void) {
// If we are in the Parsons problem -> use a different output
let outputDiv = $('#output');
let skip_faulty_found_errors = false;
let warning_box_shown = false;

if (sourceMap){
theGlobalSourcemap = sourceMap;
Expand All @@ -833,9 +828,16 @@ export function runPythonProgram(this: any, code: string, sourceMap: any, hasTur
map.hedy_range.to_line-1, map.hedy_range.to_column-1
)

if (map.error != null){
if (map.error != null) {
skip_faulty_found_errors = true;
theGlobalEditor.setIncorrectLine(range, Number(index));
}

// Only show the warning box for the first error shown
if (skip_faulty_found_errors && !warning_box_shown) {
error.showFadingWarning(ClientMessages['Execute_error'], ClientMessages['Errors_found']);
warning_box_shown = true;
}
}
}

Expand Down Expand Up @@ -1029,7 +1031,8 @@ export function runPythonProgram(this: any, code: string, sourceMap: any, hasTur
}
return;
}
if (!hasWarnings && code !== last_code && !debug) {
// Do not show success message if we found errors that we skipped
if (!hasWarnings && code !== last_code && !debug && !skip_faulty_found_errors) {
showSuccesMessage();
last_code = code;
}
Expand Down
38 changes: 19 additions & 19 deletions static/js/appbundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion static/js/appbundle.js.map

Large diffs are not rendered by default.

20 changes: 8 additions & 12 deletions static/js/modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,6 @@ export const error = {
hide() {
$('#errorbox').hide();
$('#warningbox').hide();
$('#warningbox_spinner').hide();

editor?.resize();
},
showWarning(caption: string, message: string) {
Expand All @@ -240,21 +238,19 @@ export const error = {
editor?.resize();
},

showWarningSpinner(){
$('#warningbox_icon').hide();
$('#warningbox_spinner').show();
},

hideWarningSpinner(){
$('#warningbox_icon').show();
$('#warningbox_spinner').hide();
},

show(caption: string, message: string) {
$('#errorbox .caption').text(caption);
$('#errorbox .details').html(message);
$('#errorbox').show();
editor?.resize();
},

showFadingWarning(caption: string, message: string) {
error.showWarning(caption, message);
setTimeout(function(){
$('#warningbox').fadeOut();
editor?.resize();
}, 10000);
}
}

Expand Down
6 changes: 0 additions & 6 deletions templates/incl/editor-and-output.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,6 @@
<p class="close-dialog" onclick="hedyApp.error.hide ()"><i class="fa-solid fa-xmark"></i></p>
<div class="flex">
<div class="py-1">
<div id="warningbox_spinner" style="display: none">
<svg aria-hidden="true" class="inline w-7 h-7 mr-2 text-gray-200 animate-spin dark:text-gray-600 fill-red-600" viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="currentColor"/>
<path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="currentFill"/>
</svg>
</div>
<div id="warningbox_icon">
<svg class="fill-current h-6 w-6 text-yellow-500 ltr:mr-4 rtl:ml-4" xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20">
Expand Down

0 comments on commit de5c1da

Please sign in to comment.