MCPcopy Index your code
hub / github.com/PrairieLearn/PrairieLearn / _checkState

Method _checkState

lib/code-caller.js:420–465  ·  view source on GitHub ↗
(allowedStates)

Source from the content-addressed store, hash-verified

418 }
419
420 _checkState(allowedStates) {
421 if (allowedStates && !allowedStates.includes(this.state)) {
422 const allowedStatesList = '[' + _.map(allowedStates, String).join(',') + ']';
423 return this._logError('Expected PythonCaller states ' + allowedStatesList + ' but actually have state ' + String(this.state));
424 }
425
426 let childNull, callbackNull, timeoutIDNull;
427 if (this.state == CREATED) {
428 childNull = true;
429 callbackNull = true;
430 timeoutIDNull = true;
431 } else if (this.state == WAITING) {
432 childNull = false;
433 callbackNull = true;
434 timeoutIDNull = true;
435 } else if (this.state == IN_CALL) {
436 childNull = false;
437 callbackNull = false;
438 timeoutIDNull = false;
439 } else if (this.state == EXITING) {
440 childNull = false;
441 callbackNull = true;
442 timeoutIDNull = true;
443 } else if (this.state == EXITED) {
444 childNull = true;
445 callbackNull = true;
446 timeoutIDNull = true;
447 } else {
448 return this._logError('Invalid PythonCaller state: ' + String(this.state));
449 }
450
451 if (childNull != null) {
452 if (childNull && this.child != null) return this._logError('PythonCaller state "' + String(this.state) + '": child should be null');
453 if (!childNull && this.child == null) return this._logError('PythonCaller state "' + String(this.state) + '": child should not be null');
454 }
455 if (callbackNull != null) {
456 if (callbackNull && this.callback != null) return this._logError('PythonCaller state "' + String(this.state) + '": callback should be null');
457 if (!callbackNull && this.callback == null) return this._logError('PythonCaller state "' + String(this.state) + '": callback should not be null');
458 }
459 if (timeoutIDNull != null) {
460 if (timeoutIDNull && this.timeoutID != null) return this._logError('PythonCaller state "' + String(this.state) + '": timeoutID should be null');
461 if (!timeoutIDNull && this.timeoutID == null) return this._logError('PythonCaller state "' + String(this.state) + '": timeoutID should not be null');
462 }
463
464 return true;
465 }
466}
467
468module.exports.FunctionMissingError = FunctionMissingError;

Callers 13

constructorMethod · 0.95
callMethod · 0.95
restartMethod · 0.95
doneMethod · 0.95
ensureChildMethod · 0.95
_startChildMethod · 0.95
_handleStderrDataMethod · 0.95
_handleStdoutDataMethod · 0.95
_handleStdio3DataMethod · 0.95
_handleChildExitMethod · 0.95
_handleChildErrorMethod · 0.95
_timeoutMethod · 0.95

Calls 1

_logErrorMethod · 0.95

Tested by

no test coverage detected