Add more specific error for TS web server (#187752)

This should help us better understand why the access failed
This commit is contained in:
Matt Bierner 2023-07-12 14:09:01 -07:00 committed by GitHub
parent 14b9b06a74
commit a4fde6f2eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -76,6 +76,15 @@ function toTsWatcherKind(event: 'create' | 'change' | 'delete') {
throw new Error(`Unknown event: ${event}`);
}
class AccessOutsideOfRootError extends Error {
constructor(
public readonly filepath: string,
public readonly projectRootPaths: readonly string[]
) {
super(`Could not read file outside of project root ${filepath}`);
}
}
type ServerHostWithImport = ts.server.ServerHost & { importPlugin(root: string, moduleName: string): Promise<ts.server.ModuleImportResult> };
function createServerHost(extensionUri: URI, logger: ts.server.Logger, apiClient: ApiClient | undefined, args: string[], fsWatcher: MessagePort): ServerHostWithImport {
@ -455,7 +464,7 @@ function createServerHost(extensionUri: URI, logger: ts.server.Logger, apiClient
}
if (allowRead === 'block') {
throw new Error(`Could not read file outside of project root ${filepath}`);
throw new AccessOutsideOfRootError(filepath, Array.from(projectRootPaths.keys()));
}
return uri;