Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit67fd898

Browse files
committed
Handle sync-message problems
1 parentc8e6da1 commit67fd898

File tree

6 files changed

+54
-16
lines changed

6 files changed

+54
-16
lines changed

‎core/checker.py‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ def reset(self):
4343

4444
self.console.locals.update(assert_equal=assert_equal)
4545

46-
defnon_str_input(self):
47-
raiseKeyboardInterrupt
48-
4946

5047
runner=FullRunner()
5148

‎core/runner/runner.py‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,28 @@ def serialize_syntax_error(self, exc, source_code):
4141
return {
4242
"text":friendly_syntax_error(exc,self.filename),
4343
}
44+
45+
defnon_str_input(self):
46+
# TODO do this in python_runner, then return early
47+
line=self.line
48+
self.line=""
49+
50+
ifline==1:
51+
raiseKeyboardInterrupt
52+
elifline==2:
53+
raiseRuntimeError(
54+
"The service worker for reading input isn't working. "
55+
"Try closing all futurecoder tabs, then reopening."
56+
)
57+
elifline==3:
58+
raiseRuntimeError(
59+
"This browser doesn't support reading input. "
60+
"Try upgrading to the most recent version or switching to a different browser, e.g. Chrome/Firefox. "
61+
"The browser must support SharedArrayBuffer or Service Workers."
62+
)
63+
else:
64+
# TODO raise specific exception to trigger proper feedback
65+
raiseRuntimeError(
66+
"Oops, something went wrong while reading input! "
67+
"Please report this error!"
68+
)

‎frontend/package-lock.json‎

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎frontend/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"redux-logger":"^3.0.6",
3737
"redux-thunk":"^2.3.0",
3838
"sass":"^1.32.8",
39-
"sync-message":"0.0.7"
39+
"sync-message":"0.0.8"
4040
},
4141
"scripts": {
4242
"start":"craco start",

‎frontend/src/RunCode.js‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ initWorker();
3131

3232
constchannel=makeChannel({serviceWorker:{scope:"/course/"}});
3333
if(channel?.type==="serviceWorker"){
34-
navigator.serviceWorker.register("/course/service-worker.js",{scope:"/course/"});
34+
navigator.serviceWorker.register("./service-worker.js");
3535
}
3636

3737
letinterruptBuffer=null;
@@ -64,7 +64,11 @@ export const runCode = async ({code, source}) => {
6464
if(awaitingInput){
6565
constmessageId=awaitingInput;
6666
awaitingInput=false;
67-
awaitwriteMessage(channel,{text:code},messageId);
67+
try{
68+
awaitwriteMessage(channel,{text:code},messageId);
69+
}catch{
70+
return;
71+
}
6872
bookSetState("processing",true);
6973
return;
7074
}

‎frontend/src/Worker.js‎

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import*asComlinkfrom'comlink';
66
importpythonCoreUrlfrom"./python_core.tar.load_by_url"
77
importloadPythonStringfrom"!!raw-loader!./load.py"
8-
import{readMessage,syncSleep,uuidv4}from"sync-message";
8+
import{readMessage,ServiceWorkerError,syncSleep,uuidv4}from"sync-message";
99

1010
asyncfunctiongetPackageBuffer(){
1111
constresponse=awaitfetch(pythonCoreUrl);
@@ -67,13 +67,25 @@ async function runCode(entry, channel, interruptBuffer, outputCallback, inputCal
6767
awaitpyodideReadyPromise;
6868

6969
constfullInputCallback=(data)=>{
70-
constmessageId=uuidv4();
71-
inputCallback(messageId,toObject(data));
72-
constresult=readMessage(channel,messageId).text;
73-
if(result==null){
74-
returnnull;
70+
try{
71+
if(!channel){
72+
return3;// browser not supported
73+
}
74+
constmessageId=uuidv4();
75+
inputCallback(messageId,toObject(data));
76+
constresult=readMessage(channel,messageId).text;
77+
if(result==null){
78+
return1;// interrupt
79+
}
80+
returnresult+"\n";
81+
}catch(e){
82+
if(einstanceofServiceWorkerError){
83+
return2;// suggesting closing all tabs and reopening
84+
}else{
85+
console.error(e);
86+
return4;// general error
87+
}
7588
}
76-
returnresult+"\n";
7789
}
7890

7991
if(interruptBuffer){

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp