{"record":{"id":"1d5d4bdaf018f9e6","repo":"microsoft/TypeScript","slug":"no-script-with-name-filename","errorCode":null,"errorMessage":"No script with name '\" + fileName + \"'","messagePattern":"No script with name '\" \\+ fileName \\+ \"'","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/harness/harnessLanguageService.ts","lineNumber":335,"sourceCode":"            const newFileName = updater(key);\r\n            if (newFileName !== undefined) {\r\n                this.scriptInfos.delete(key);\r\n                this.scriptInfos.set(newFileName, scriptInfo);\r\n                scriptInfo.fileName = newFileName;\r\n            }\r\n        });\r\n    }\r\n\r\n    public editScript(fileName: string, start: number, end: number, newText: string): void {\r\n        const script = this.getScriptInfo(fileName);\r\n        if (script) {\r\n            script.editContent(start, end, newText);\r\n            this.vfs.mkdirpSync(vpath.dirname(fileName));\r\n            this.vfs.writeFileSync(fileName, script.content);\r\n            return;\r\n        }\r\n\r\n        throw new Error(\"No script with name '\" + fileName + \"'\");\r\n    }\r\n\r\n    public openFile(_fileName: string, _content?: string, _scriptKindName?: string): void {/*overridden*/}\r\n\r\n    /**\r\n     * @param line 0 based index\r\n     * @param col 0 based index\r\n     */\r\n    public positionToLineAndCharacter(fileName: string, position: number): ts.LineAndCharacter {\r\n        const script: ScriptInfo = this.getScriptInfo(fileName)!;\r\n        assert.isOk(script);\r\n        return ts.computeLineAndCharacterOfPosition(script.getLineMap(), position);\r\n    }\r\n\r\n    public lineAndCharacterToPosition(fileName: string, lineAndCharacter: ts.LineAndCharacter): number {\r\n        const script: ScriptInfo = this.getScriptInfo(fileName)!;\r\n        assert.isOk(script);\r\n        return ts.computePositionOfLineAndCharacter(script.getLineMap(), lineAndCharacter.line, lineAndCharacter.character);\r","sourceCodeStart":317,"sourceCodeEnd":353,"githubUrl":"https://github.com/microsoft/TypeScript/blob/b465fdbfe175304d9b977da137b2c178ae1091d3/src/harness/harnessLanguageService.ts#L317-L353","documentation":"Thrown by LanguageServiceAdapterHost.editScript (harnessLanguageService.ts:335) when no ScriptInfo is registered for the given fileName. editScript is meant to mutate an already-known file; if getScriptInfo returns falsy the harness refuses to fabricate one.","triggerScenarios":"A test calls `host.editScript(\"/path/a.ts\", start, end, text)` without first adding the file via addScript/openFile, or uses a fileName whose casing/path does not exactly match the registered one.","commonSituations":"Forgetting the setup `openFile`/`addScript` step; using forward vs back slashes inconsistently; case mismatch on a case-sensitive VFS; editing a file that was added to a different host instance.","solutions":["Register the file first: `host.openFile(fileName, content)` or `addScript(fileName, ScriptSnapshot.fromString(content), /*version*/ \"0\")`.","Verify the fileName passed to editScript is byte-identical (slashes, case, absolute path) to the one used at registration.","If the file lives in a different host/project, route the edit through that host.","Add an assertion in test setup that getScriptInfo(fileName) is truthy before editScript."],"exampleFix":"// before\nhost.editScript(\"/a.ts\", 0, 0, \"export const x = 1;\\n\");\n// throws: No script with name '/a.ts'\n\n// after — register first\nhost.openScript(\"/a.ts\", \"\");\nhost.editScript(\"/a.ts\", 0, 0, \"export const x = 1;\\n\");","handlingStrategy":"validation","validationCode":"// Ensure the script exists before editing.\nif (!host.getScriptInfo(fileName)) {\n  throw new Error(`Cannot edit unregistered script: ${fileName}. Call openScript/addScript first.`);\n}\nhost.editScript(fileName, start, end, newText);","typeGuard":"function scriptIsRegistered(host: LanguageServiceHost, fileName: string): boolean {\n  return !!host.getScriptInfo(fileName);\n}","tryCatchPattern":null,"preventionTips":["Always openScript/addScript in setup before any editScript call.","Use the exact registered fileName (slashes, case, absolute path).","Assert getScriptInfo is truthy in a setup helper to fail fast."],"tags":["test-harness","language-service","script-info","setup"],"backgroundTag":null,"analyzedSha":"b465fdbfe175304d9b977da137b2c178ae1091d3","analyzedAt":"2026-08-12T05:38:42.698Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}