Skip to content

Commit

Permalink
fix: better handle step transition error (#457)
Browse files Browse the repository at this point in the history
  • Loading branch information
npaton committed Dec 10, 2023
1 parent 254e004 commit 98d72e9
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 58 deletions.
5 changes: 5 additions & 0 deletions .changeset/catch-transition-errors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@empirica/core": patch
---

Handle errors in step state transition requests.
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/charmbracelet/lipgloss v0.5.0
github.com/cortesi/moddwatch v0.0.0-20210323234936-df014e95c743
github.com/davecgh/go-spew v1.1.1
github.com/empiricaly/tajriba v1.5.0
github.com/empiricaly/tajriba v1.5.3
github.com/go-playground/validator/v10 v10.11.0
github.com/jpillora/backoff v1.0.0
github.com/json-iterator/go v1.1.12
Expand All @@ -30,8 +30,8 @@ require (
github.com/spf13/viper v1.12.0
github.com/twmb/murmur3 v1.1.6
golang.org/x/exp v0.0.0-20220609121020-a51bd0440498
golang.org/x/term v0.11.0
golang.org/x/text v0.12.0
golang.org/x/term v0.13.0
golang.org/x/text v0.13.0
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
)
Expand Down Expand Up @@ -85,10 +85,10 @@ require (
github.com/urfave/cli/v2 v2.25.5 // indirect
github.com/vektah/gqlparser/v2 v2.5.8 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/tools v0.11.1 // indirect
gopkg.in/ini.v1 v1.66.6 // indirect
)
24 changes: 12 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgryski/trifles v0.0.0-20200323201526-dd97f9abfb48 h1:fRzb/w+pyskVMQ+UbP35JkH8yB7MYb4q/qhBarqZE6g=
github.com/dgryski/trifles v0.0.0-20200323201526-dd97f9abfb48/go.mod h1:if7Fbed8SFyPtHLHbg49SI7NAdJiC5WIA09pe59rfAA=
github.com/empiricaly/tajriba v1.5.0 h1:ALpM3WyahVfiotLIY93ILYN5rEbdJvsLGLcTG9cG9rA=
github.com/empiricaly/tajriba v1.5.0/go.mod h1:TqAM0iRbN78gE5vnZ1Ot6PQOidfYM5FwIdoU/UB+wrE=
github.com/empiricaly/tajriba v1.5.3 h1:I4ZKrp34Da1zFiREsPiReZUueQznNJh9vKBckKC0WjE=
github.com/empiricaly/tajriba v1.5.3/go.mod h1:WVNK+x2GxPx69gIHrKGHQG6HdcZKvaCAb7B8p8vk38c=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
Expand Down Expand Up @@ -356,8 +356,8 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk=
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
Expand Down Expand Up @@ -427,8 +427,8 @@ golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v
golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14=
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -498,12 +498,12 @@ golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.11.0 h1:F9tnn/DA/Im8nCwm+fX+1/eBwi4qFjRT++MhtVC4ZX0=
golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU=
golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek=
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand All @@ -512,8 +512,8 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down
2 changes: 1 addition & 1 deletion lib/@empirica/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@
"unocss": "0.51.4"
},
"dependencies": {
"@empirica/tajriba": "1.5.2",
"@empirica/tajriba": "1.5.3",
"@swc/helpers": "0.4.2",
"@unocss/reset": "^0.51.4",
"archiver": "5.3.1",
Expand Down
47 changes: 30 additions & 17 deletions lib/@empirica/core/src/admin/classic/classic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,14 +610,21 @@ export function Classic({

ctx.addLinks([{ link: true, participantIDs, nodeIDs }]);

ctx.addTransitions([
{
from: State.Created,
to: State.Running,
nodeID: timerID,
cause: "stage start",
},
]);
ctx
.addTransitions([
{
from: State.Created,
to: State.Running,
nodeID: timerID,
cause: "stage start",
},
])
.catch((err) => {
debug(`stage start: ${err}`);
})
.then(() => {
trace(`stage start, transitioned`);
});
}
);

Expand Down Expand Up @@ -646,15 +653,21 @@ export function Classic({
);

if (haveAllPlayersSubmitted) {
ctx.addTransitions([
{
from: State.Running,
to: State.Ended,
nodeID: isString(playerStage.stage!.get("timerID")),
cause: "players submitted",
},
]);
trace(`all player submitted, transitioning`);
ctx
.addTransitions([
{
from: State.Running,
to: State.Ended,
nodeID: isString(playerStage.stage!.get("timerID")),
cause: "players submitted",
},
])
.catch((err) => {
debug(`players submitted: ${err}`);
})
.then(() => {
trace(`all player submitted, transitioned`);
});
} else {
trace(`not all player submitted`);
}
Expand Down
40 changes: 25 additions & 15 deletions lib/@empirica/core/src/admin/classic/lobby.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,21 @@ async function setupIndividualLobbyTimeout(
player.set(lobbyTimerKey, stepID);
player.set(individualTimerGameKey, game.id);

ctx.addTransitions([
{
from: State.Created,
to: State.Running,
nodeID: stepID,
cause: "lobby timer start",
},
]);
ctx
.addTransitions([
{
from: State.Created,
to: State.Running,
nodeID: stepID,
cause: "individual lobby timer start",
},
])
.catch((err) => {
error(`individual lobby timer start: ${err}`);
})
.then(() => {
trace(`individual lobby timer start, transitioned`);
});
}

async function expiredIndividualLobbyTimeout(
Expand Down Expand Up @@ -177,18 +184,21 @@ async function setupSharedLobbyTimeout(
debug("lobby: lobby created", stepID);
game.set(lobbyTimerKey, stepID);

try {
await ctx.addTransitions([
await ctx
.addTransitions([
{
from: State.Created,
to: State.Running,
nodeID: stepID,
cause: "lobby timer start",
cause: "shared lobby timer start",
},
]);
} catch (e) {
debug("lobby: failed to start lobby timeout", e);
}
])
.catch((err) => {
debug(`shared lobby timer start: ${err}`);
})
.then(() => {
trace(`shared lobby timer start, transitioned`);
});
}

async function expiredSharedLobbyTimeout(
Expand Down
11 changes: 9 additions & 2 deletions lib/@empirica/core/src/admin/classic/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import { AddScopePayload, StepPayload } from "../context";
import { EventContext } from "../events";
import { Scope } from "../scopes";
import { AttrInput, attrs, scopeConstructor } from "./helpers";
import { debug, trace } from "console";

const isString = z.string().parse;
const isOptionalNumber = z.number().optional().parse;

export const endedStatuses = ["ended", "terminated", "failed"];
export type EndedStatuses = (typeof endedStatuses)[number];
export type EndedStatuses = typeof endedStatuses[number];

const reservedKeys = [
"batchID",
Expand Down Expand Up @@ -936,7 +937,13 @@ export class Stage extends GameOwned {
nodeID: this.get("timerID") as string,
cause: reason,
},
]);
])
.catch((err) => {
debug(`stage end: ${err}`);
})
.then(() => {
trace(`stage end, transitioned`);
});
}

async createPlayerStage(player: Player) {
Expand Down
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 98d72e9

Please sign in to comment.