Skip to content

Commit

Permalink
send error if obtaining of types-registry package failed (#14573) (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
vladima committed Mar 10, 2017
1 parent 6e8c44f commit 8f41444
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 3 deletions.
11 changes: 11 additions & 0 deletions src/server/protocol.ts
Expand Up @@ -2127,6 +2127,17 @@ namespace ts.server.protocol {
payload: any;
}

export type TypesInstallerInitializationFailedEventName = "typesInstallerInitializationFailed";

export interface TypesInstallerInitializationFailedEvent extends Event {
event: TypesInstallerInitializationFailedEventName;
body: TypesInstallerInitializationFailedEventBody;
}

export interface TypesInstallerInitializationFailedEventBody {
message: string;
}

export type TypingsInstalledTelemetryEventName = "typingsInstalled";

export interface TypingsInstalledTelemetryEventBody extends TelemetryEventBody {
Expand Down
14 changes: 13 additions & 1 deletion src/server/server.ts
Expand Up @@ -304,11 +304,23 @@ namespace ts.server {
});
}

private handleMessage(response: SetTypings | InvalidateCachedTypings | BeginInstallTypes | EndInstallTypes) {
private handleMessage(response: SetTypings | InvalidateCachedTypings | BeginInstallTypes | EndInstallTypes | InitializationFailedResponse) {
if (this.logger.hasLevel(LogLevel.verbose)) {
this.logger.info(`Received response: ${JSON.stringify(response)}`);
}

if (response.kind === EventInitializationFailed) {
if (!this.eventSender) {
return;
}
const body: protocol.TypesInstallerInitializationFailedEventBody = {
message: response.message
}
const eventName: protocol.TypesInstallerInitializationFailedEventName = "typesInstallerInitializationFailed";
this.eventSender.event(body, eventName);
return;
}

if (response.kind === EventBeginInstallTypes) {
if (!this.eventSender) {
return;
Expand Down
1 change: 1 addition & 0 deletions src/server/shared.ts
Expand Up @@ -5,6 +5,7 @@ namespace ts.server {
export const ActionInvalidate: ActionInvalidate = "action::invalidate";
export const EventBeginInstallTypes: EventBeginInstallTypes = "event::beginInstallTypes";
export const EventEndInstallTypes: EventEndInstallTypes = "event::endInstallTypes";
export const EventInitializationFailed: EventInitializationFailed = "event::initializationFailed";

export namespace Arguments {
export const GlobalCacheLocation = "--globalTypingsCacheLocation";
Expand Down
8 changes: 7 additions & 1 deletion src/server/types.ts
Expand Up @@ -47,9 +47,15 @@ declare namespace ts.server {
export type ActionInvalidate = "action::invalidate";
export type EventBeginInstallTypes = "event::beginInstallTypes";
export type EventEndInstallTypes = "event::endInstallTypes";
export type EventInitializationFailed = "event::initializationFailed";

export interface TypingInstallerResponse {
readonly kind: ActionSet | ActionInvalidate | EventBeginInstallTypes | EventEndInstallTypes;
readonly kind: ActionSet | ActionInvalidate | EventBeginInstallTypes | EventEndInstallTypes | EventInitializationFailed;
}

export interface InitializationFailedResponse extends TypingInstallerResponse {
readonly kind: EventInitializationFailed;
readonly message: string;
}

export interface ProjectResponse extends TypingInstallerResponse {
Expand Down
14 changes: 13 additions & 1 deletion src/server/typingsInstaller/nodeTypingsInstaller.ts
Expand Up @@ -76,6 +76,8 @@ namespace ts.server.typingsInstaller {
private readonly npmPath: string;
readonly typesRegistry: Map<void>;

private delayedInitializationError: InitializationFailedResponse;

constructor(globalTypingsCacheLocation: string, throttleLimit: number, log: Log) {
super(
sys,
Expand All @@ -101,13 +103,23 @@ namespace ts.server.typingsInstaller {
if (this.log.isEnabled()) {
this.log.writeLine(`Error updating ${TypesRegistryPackageName} package: ${(<Error>e).message}`);
}
// store error info to report it later when it is known that server is already listening to events from typings installer
this.delayedInitializationError = {
kind: "event::initializationFailed",
message: (<Error>e).message
};
}

this.typesRegistry = loadTypesRegistryFile(getTypesRegistryFileLocation(globalTypingsCacheLocation), this.installTypingHost, this.log);
}

listen() {
process.on("message", (req: DiscoverTypings | CloseProject) => {
if (this.delayedInitializationError) {
// report initializationFailed error
this.sendResponse(this.delayedInitializationError);
this.delayedInitializationError = undefined;
}
switch (req.kind) {
case "discover":
this.install(req);
Expand All @@ -118,7 +130,7 @@ namespace ts.server.typingsInstaller {
});
}

protected sendResponse(response: SetTypings | InvalidateCachedTypings | BeginInstallTypes | EndInstallTypes) {
protected sendResponse(response: SetTypings | InvalidateCachedTypings | BeginInstallTypes | EndInstallTypes | InitializationFailedResponse) {
if (this.log.isEnabled()) {
this.log.writeLine(`Sending response: ${JSON.stringify(response)}`);
}
Expand Down

0 comments on commit 8f41444

Please sign in to comment.