{"record":{"id":"5b4719e62b6704e4","repo":"affaan-m/ECC","slug":"version-not-found-v-normalizedtargetversion","errorCode":null,"errorMessage":"Version not found: v${normalizedTargetVersion}","messagePattern":"Version not found: v(.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/lib/skill-evolution/versioning.js","lineNumber":196,"sourceCode":"  return {\n    version: nextVersion,\n    path: snapshotPath,\n    created_at: createdAt,\n  };\n}\n\nfunction rollbackTo(skillPath, targetVersion, options = {}) {\n  const normalizedTargetVersion = Number(targetVersion);\n  if (!Number.isInteger(normalizedTargetVersion) || normalizedTargetVersion <= 0) {\n    throw new Error(`Invalid target version: ${targetVersion}`);\n  }\n\n  ensureSkillExists(skillPath);\n  ensureSkillVersioning(skillPath);\n\n  const targetPath = path.join(getVersionsDir(skillPath), `v${normalizedTargetVersion}.md`);\n  if (!fs.existsSync(targetPath)) {\n    throw new Error(`Version not found: v${normalizedTargetVersion}`);\n  }\n\n  const currentVersion = getCurrentVersion(skillPath);\n  const targetContent = fs.readFileSync(targetPath, 'utf8');\n  fs.writeFileSync(getSkillFilePath(skillPath), targetContent, 'utf8');\n\n  const createdVersion = createVersion(skillPath, {\n    timestamp: options.timestamp,\n    reason: options.reason || `rollback to v${normalizedTargetVersion}`,\n    author: options.author || null,\n  });\n\n  appendEvolutionRecord(skillPath, 'amendments', {\n    event: 'rollback',\n    version: createdVersion.version,\n    source_version: currentVersion,\n    target_version: normalizedTargetVersion,\n    reason: options.reason || null,","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/lib/skill-evolution/versioning.js#L178-L214","documentation":"rollbackTo throws this after validating the version number when the corresponding snapshot file v<n>.md does not exist in the skill's versions directory. The version integer is valid but there is no stored snapshot to roll back to. This protects against restoring an empty or wrong file.","triggerScenarios":"Calling rollbackTo with an integer > 0 that was never captured, e.g. version 5 when only v1–v3 exist; versions directory deleted or pruned; wrong skillPath so the lookup hits a directory without that history.","commonSituations":"Guessing the latest version number instead of listing files; CI cleaning up versions/ directories as build artifacts; switching machines without copying version history; rolling back a different skill than the one whose history you consulted.","solutions":["List files in the skill's versions directory and pick an existing v<n>.md version number","Restore the missing versions directory from git or backups","Confirm the skillPath points at the skill whose history contains that version","Capture the missing version via the library's save/commit-version flow before rolling back"],"exampleFix":"// before\nawait rollbackTo(skillPath, 9); // v9.md never saved\n// after\nconst available = fs.readdirSync(getVersionsDir(skillPath)).map(f => parseInt(f.slice(1)));\nawait rollbackTo(skillPath, Math.max(...available));","handlingStrategy":"fallback","validationCode":"const fs = require('fs');\nconst target = require('path').join(versionsDir, `v${v}.md`);\nif (!fs.existsSync(target)) {\n  const available = fs.readdirSync(versionsDir)\n    .filter(f => /^v\\d+\\.md$/.test(f))\n    .map(f => parseInt(f.slice(1)));\n  console.error(`v${v} missing; available: ${available.sort((a,b)=>a-b).join(', ')}`);\n}","typeGuard":"function versionExists(skillPath, v) {\n  return fs.existsSync(path.join(getVersionsDir(skillPath), `v${v}.md`));\n}","tryCatchPattern":"try {\n  await rollbackTo(skillPath, v);\n} catch (err) {\n  if (err.message.startsWith('Version not found')) {\n    const match = err.message.match(/v(\\d+)/);\n    console.error(`Snapshot v${match[1]} absent — restore versions dir or pick another`);\n  } else throw err;\n}","preventionTips":["List available versions (readdir of versions dir) before rolling back","Never treat versions/ directories as disposable build artifacts in CI clean steps","Commit version history to git or back it up","Derive target versions from actual files, not guesses about history length"],"tags":["filesystem","versions"],"backgroundTag":"resource-not-found","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}