Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.
JavaScript apple-watchbodyweightdockerfitnessfitness-trackergymhealthiosmcpnodejspasskeysprogressive-web-applicationspwareactself-hostedself-hostingvitewebauthnweightliftingworkout-tracker
Coach: an added routine with a null entry goes back for repair (#652)
Duarte Santosbf00183666e2
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 4ce4f2566..cd4c8ab42 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -42,6 +42,8 @@ asking for anything, promise.- Cardio the Coach prescribes on a non-cardio exercise (kettlebell swings for 15 minutes) stays15 minutes instead of turning into sets with no target, in new plans, in review additions andin shared plan files (#640, thanks @rudycelekli for spotting the review side).+- A Coach review that adds a routine with an empty slot in it gets a second try instead of+ failing outright (thanks @rudycelekli).## v1.4.2 (2026-10-18)diff --git a/api/coach/core/validate.js b/api/coach/core/validate.jsindex b15bbb412..444ef44c7 100644--- a/api/coach/core/validate.js+++ b/api/coach/core/validate.js@@ -448,8 +448,16 @@ export function validateReview(data, plan, ctx = {}) {// the routine the model asked for minus the exercises it could not have, and hand that// to someone as if it were what they were shown.const listed = Array.isArray(a.ex) ? a.ex : [];- const bad = listed.find(e => !e || !isStr(e.id) || !knownEx(e.id));- if (bad) { errors.push(`${where}.after.ex "${bad.id}" is not in the exercise library — use an id from the library provided in the payload`); return; }+ // By index: find() hands back the entry itself, and a null in the list was falsy enough+ // to pass this check and crash on the next line instead of going back for repair.+ const badAt = listed.findIndex(e => !e || typeof e !== 'object' || !isStr(e.id) || !knownEx(e.id));+ if (badAt >= 0) {+ const bad = listed[badAt];+ errors.push(bad && typeof bad === 'object' && isStr(bad.id)+ ? `${where}.after.ex "${bad.id}" is not in the exercise library — use an id from the library provided in the payload`+ : `${where}.after.ex[${badAt}] is not an exercise — each entry needs an id from the library provided in the payload`);+ return;+ }const offEq = listed.find(e => offEquipment(ctx, e.id));if (offEq) { errors.push(OFF_EQUIPMENT(`${where}.after.ex`, offEq.id)); return; }const ex = listed.slice(0, MAX_EX_PER_ROUTINE);diff --git a/api/test/validate.test.js b/api/test/validate.test.jsindex dfe4a8b1c..c000fcc42 100644--- a/api/test/validate.test.js+++ b/api/test/validate.test.js@@ -225,6 +225,16 @@ test('cardio on a non-cardio exercise keeps its mode, minutes and pace (#640)',assert.equal(reps.proposal.changes[0].after.min, undefined);});+test('an added routine with a null or junk entry goes back for repair instead of crashing', () => {+ for (const junk of [null, false, 0, 'x', { sets: 3 }]) {+ const r = review([change({ type: 'add-routine', target: {}, after: { name: 'C', ex: [{ id: '0001', sets: 3, reps: 10 }, junk] } })]);+ assert.equal(r.ok, false, JSON.stringify(junk));+ assert.ok(r.errors.some(e => e.includes('after.ex[1]')), JSON.stringify(r.errors));+ }+ const unknown = review([change({ type: 'add-routine', target: {}, after: { name: 'C', ex: [{ id: 'made-up' }] } })]);+ assert.ok(unknown.errors.some(e => e.includes('"made-up"')), 'an unknown id is still named back to the model');+});+test('adding an exercise requires a real library id', () => {const ok = review([change({ type: 'add-exercise', target: { routineId: 'r1' }, after: { id: '0009', sets: 3, reps: 12 } })]);assert.equal(ok.ok, true);