{"record":{"id":"eaedb4c25f2e0a2e","repo":"microsoft/typescript-go","slug":"invalid-uri-uri","errorCode":null,"errorMessage":"invalid URI: ${uri}","messagePattern":"invalid URI: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"_packages/native-preview/src/api/path.ts","lineNumber":533,"sourceCode":"        }\r\n\r\n        // Local file - fix Windows path by removing leading slash before volume\r\n        const path = decodeURIComponent(parsed.pathname);\r\n        if (path.length >= 3 && path.charCodeAt(0) === CharacterCodesSlash) {\r\n            const [volume, rest, ok] = splitVolumePath(path.substring(1));\r\n            if (ok) {\r\n                return volume + rest;\r\n            }\r\n        }\r\n        return path;\r\n    }\r\n\r\n    // Leave all other URIs escaped so we can round-trip them.\r\n    // Convert to dynamic file name format: ^/scheme/authority/path\r\n\r\n    const colonIndex = uri.indexOf(\":\");\r\n    if (colonIndex === -1) {\r\n        throw new Error(\"invalid URI: \" + uri);\r\n    }\r\n\r\n    const scheme = uri.substring(0, colonIndex);\r\n    let path = uri.substring(colonIndex + 1);\r\n\r\n    let authority = \"ts-nul-authority\";\r\n    if (path.startsWith(\"//\")) {\r\n        const rest = path.substring(2);\r\n        const slashIndex = rest.indexOf(\"/\");\r\n        if (slashIndex === -1) {\r\n            throw new Error(\"invalid URI: \" + uri);\r\n        }\r\n        authority = rest.substring(0, slashIndex);\r\n        path = rest.substring(slashIndex + 1);\r\n    }\r\n\r\n    return \"^/\" + scheme + \"/\" + authority + \"/\" + path;\r\n}\r","sourceCodeStart":515,"sourceCodeEnd":551,"githubUrl":"https://github.com/microsoft/typescript-go/blob/1bcfa18d79a3be41772223d5c05dfe4480e614ff/_packages/native-preview/src/api/path.ts#L515-L551","documentation":"In documentURIToFileName, any URI that is not 'bundled://' and not 'file://' is treated as scheme-based and converted to the dynamic '^/scheme/authority/path' form. This requires a ':' separating the scheme from the rest. A string without a colon has no scheme at all, so it is not a URI in any recognizable sense and the function throws rather than guessing.","triggerScenarios":"Calling documentURIToFileName with a bare path: 'src/index.ts', './foo.ts', '/abs/path/file.ts' (POSIX absolute paths start with '/', not 'file://'), or any relative/extensionless string with no scheme.","commonSituations":"Passing file system paths where document URIs are expected — e.g. feeding LSP document URIs from an editor but forgetting some clients send raw paths; migration from APIs that accepted both paths and URIs.","solutions":["Convert plain paths to 'file://' URIs first (or call fileNameToDocumentURI which accepts raw paths)","If integrating with LSP, ensure textDocument URIs are used, not fileName fields","Pre-check uri.includes(':') and handle the path case separately"],"exampleFix":"// before\ndocumentURIToFileName(\"/home/user/project/a.ts\"); // throws: no scheme\n\n// after\ndocumentURIToFileName(\"file:///home/user/project/a.ts\");","handlingStrategy":"validation","validationCode":"const looksLikeUri = (s: string) => /^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(s);","typeGuard":"function isDocumentUri(s: string): boolean {\n  return s.startsWith(\"bundled:///\") || s.startsWith(\"file://\") || /^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(s);\n}","tryCatchPattern":"try { name = documentURIToFileName(uri); } catch (e) { if ((e as Error).message.startsWith(\"invalid URI\")) { uri = `file://${uri}`; name = documentURIToFileName(uri); } else throw e; }","preventionTips":["Prefix plain paths with 'file://' (or use fileNameToDocumentURI which accepts paths)","Use LSP document URIs, not fileName strings, when the API expects URIs","Pre-check that the string has a scheme ('scheme:') before calling"],"tags":["typescript","uri","path","validation"],"backgroundTag":null,"analyzedSha":"1bcfa18d79a3be41772223d5c05dfe4480e614ff","analyzedAt":"2026-08-16T02:12:00.115Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}