{"record":{"id":"10cb777c7026564a","repo":"Fission-AI/OpenSpec","slug":"cannot-fork-schema-source-onto-itself-choose","errorCode":null,"errorMessage":"Cannot fork schema '${source}' onto itself; choose a different destination name","messagePattern":"Cannot fork schema '(.+?)' onto itself; choose a different destination name","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/commands/schema.ts","lineNumber":748,"sourceCode":"        parseSchema(\n          fs.readFileSync(path.join(trustedSourceDir, 'schema.yaml'), 'utf-8')\n        );\n\n        // Check destination\n        const schemasDir = getProjectSchemasDir(projectRoot);\n        const destinationDir = path.join(schemasDir, destinationName);\n\n        // Reject a self-fork. Forking a schema onto itself with --force would\n        // otherwise remove the source at the replacement step below and then\n        // fail the copy, destroying the only copy of the schema. Resolve both\n        // sides to their real paths (realpathSync follows symlinks; path.resolve\n        // is a fallback only for a destination that does not exist yet) so a\n        // symlink or a `.`/`..` spelling of the same directory is still caught.\n        const resolvedDestination = fs.existsSync(destinationDir)\n          ? fs.realpathSync(destinationDir)\n          : path.resolve(destinationDir);\n        if (resolvedDestination === trustedSourceDir) {\n          throw new Error(\n            `Cannot fork schema '${source}' onto itself; choose a different destination name`\n          );\n        }\n\n        const destinationExists = fs.existsSync(destinationDir);\n        if (destinationExists && !options?.force) {\n          if (options?.json) {\n            console.log(JSON.stringify({\n              forked: false,\n              error: `Schema '${destinationName}' already exists`,\n              suggestion: 'Use --force to overwrite',\n            }, null, 2));\n          } else {\n            console.error(`Error: Schema '${destinationName}' already exists at ${destinationDir}`);\n            console.error('Use --force to overwrite');\n          }\n          process.exitCode = 1;\n          return;","sourceCodeStart":730,"sourceCodeEnd":766,"githubUrl":"https://github.com/Fission-AI/OpenSpec/blob/6926ccb18afa4ff621112813e9968334576ee11a/src/commands/schema.ts#L730-L766","documentation":"Error \"Cannot fork schema '${source}' onto itself; choose a different destination name\" thrown in Fission-AI/OpenSpec.","triggerScenarios":"Thrown at src/commands/schema.ts:748 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"6926ccb18afa4ff621112813e9968334576ee11a","analyzedAt":"2026-08-25T12:29:45.729Z","schemaVersion":2},"datasetVersion":"2026-08-25T16:17:27.014Z"}