Skip to content

Commit

Permalink
DEV2-3175: Fix error logs (#1212)
Browse files Browse the repository at this point in the history
  • Loading branch information
Assaf Sapir authored Jul 19, 2023
1 parent 352eeff commit 94cee5b
Show file tree
Hide file tree
Showing 29 changed files with 97 additions and 61 deletions.
5 changes: 3 additions & 2 deletions src/assistant/AssistantHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { ASSISTANT_IGNORE_REFRESH_COMMAND } from "./globals";
import { IgnoreAssistantSelection } from "./IgnoreAssistantSelection";
import { AcceptAssistantSelection } from "./AcceptAssistantSelection";
import { setDecorators } from "./diagnostics";
import { Logger } from "../utils/logger";

const IGNORE_VALUE = "__IGNORE__";

Expand Down Expand Up @@ -48,7 +49,7 @@ export async function assistantSelectionHandler(
);
void setState(eventData);
} catch (error) {
console.error(error);
Logger.error(error);
}
}

Expand Down Expand Up @@ -79,7 +80,7 @@ export async function assistantIgnoreHandler(
);
void setState(eventData);
} catch (error) {
console.error(error);
Logger.error(error);
}
}

Expand Down
15 changes: 8 additions & 7 deletions src/binary/Binary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
BINARY_RESTART_EVENT,
} from "../globals/consts";
import { sleep, waitForRejection } from "../utils/utils";
import { Logger } from "../utils/logger";

type RestartCallback = () => void;

Expand Down Expand Up @@ -62,7 +63,7 @@ export default class Binary {
}

if (this.isBinaryDead()) {
console.warn("Binary died. It is being restarted.");
Logger.warn("Binary died. It is being restarted.");
await this.restartChild();

return null;
Expand All @@ -78,10 +79,10 @@ export default class Binary {

return result;
} catch (err) {
console.error(err);
Logger.error(err);
this.requestFailures += 1;
if (this.requestFailures > REQUEST_FAILURES_THRESHOLD) {
console.warn("Binary not returning results, it is being restarted.");
Logger.warn("Binary not returning results, it is being restarted.");
await this.restartChild();
}
} finally {
Expand Down Expand Up @@ -127,23 +128,23 @@ export default class Binary {
this.proc = proc;
this.proc.unref(); // AIUI, this lets Node exit without waiting for the child
this.proc.on("exit", (code, signal) => {
console.warn(
Logger.warn(
`Binary child process exited with code ${code ?? "unknown"} signal ${
signal ?? "unknown"
}`
);
void this.restartChild();
});
this.proc.on("error", (error) => {
console.warn(`Binary child process error: ${error.message}`);
Logger.warn(`Binary child process error: ${error.message}`);
void this.restartChild();
});
this.proc.stdin?.on("error", (error) => {
console.warn(`Binary child process stdin error: ${error.message}`);
Logger.warn(`Binary child process stdin error: ${error.message}`);
void this.restartChild();
});
this.proc.stdout?.on("error", (error) => {
console.warn(`Binary child process stdout error: ${error.message}`);
Logger.warn(`Binary child process stdout error: ${error.message}`);
void this.restartChild();
});

Expand Down
3 changes: 2 additions & 1 deletion src/binary/binaryFetcher/activeFileHandler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as fs from "fs";
import { getActivePath, versionPath } from "../paths";
import { isBadVersion } from "./binaryValidator";
import { Logger } from "../../utils/logger";

export default function handleActiveFile(): string | null {
try {
Expand All @@ -17,7 +18,7 @@ export default function handleActiveFile(): string | null {
}
}
} catch (e) {
console.error(
Logger.error(
"Error handling .active file. Falling back to semver sorting",
e
);
Expand Down
3 changes: 2 additions & 1 deletion src/binary/binaryFetcher/binaryValidator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as semver from "semver";
import { asyncExists } from "../../utils/file.utils";
import { runProcess } from "../runProcess";
import { Logger } from "../../utils/logger";

// A patch to skip this specific version, because of a critical issue in the version
const BAD_VERSION = "4.0.47";
Expand Down Expand Up @@ -28,7 +29,7 @@ export default async function isValidBinary(version: string): Promise<boolean> {

return new Promise((resolve) => {
setTimeout(() => {
console.error(`validating ${version} timeout`);
Logger.error(`validating ${version} timeout`);
resolve(false);
}, TWO_SECONDS_TIMEOUT);

Expand Down
3 changes: 2 additions & 1 deletion src/binary/binaryFetcher/existingVersionHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import sortBySemver from "../../utils/semver.utils";
import { asyncFind } from "../../utils/utils";
import isValidBinary, { isBadVersion } from "./binaryValidator";
import { getRootPath, versionPath } from "../paths";
import { Logger } from "../../utils/logger";

export default async function handleExistingVersion(): Promise<string | null> {
try {
Expand All @@ -13,7 +14,7 @@ export default async function handleExistingVersion(): Promise<string | null> {
const versions = sortBySemver(validVersions).map(versionPath);
return await asyncFind(versions, isValidBinary);
} catch (e) {
console.error(
Logger.error(
"Error handling existing version. Falling back to downloading",
e
);
Expand Down
11 changes: 6 additions & 5 deletions src/binary/requests/fileMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/* eslint-disable
@typescript-eslint/no-explicit-any,
@typescript-eslint/no-unsafe-assignment,
@typescript-eslint/no-unsafe-member-access,
/* eslint-disable
@typescript-eslint/no-explicit-any,
@typescript-eslint/no-unsafe-assignment,
@typescript-eslint/no-unsafe-member-access,
@typescript-eslint/no-unsafe-return
*/

import { Logger } from "../../utils/logger";
import { tabNineProcess } from "./requests";

export async function getFileMetadata(path: string): Promise<unknown> {
Expand All @@ -13,7 +14,7 @@ export async function getFileMetadata(path: string): Promise<unknown> {
});

if (response.error) {
console.error("Failed to get file metadata", response);
Logger.error("Failed to get file metadata", response);
return null;
}

Expand Down
3 changes: 2 additions & 1 deletion src/binary/requests/notifyWorkspaceChanged.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Logger } from "../../utils/logger";
import { tabNineProcess } from "./requests";

interface NotifyWorkspaceChangedRequest {
Expand All @@ -16,7 +17,7 @@ function notifyWorkspaceChanged(
},
5000
)
.catch(console.error);
.catch((e) => Logger.error(e));
}

export default notifyWorkspaceChanged;
5 changes: 3 additions & 2 deletions src/binary/requests/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import CompletionOrigin from "../../CompletionOrigin";
import Binary from "../Binary";
import { State } from "../state";
import { StateType } from "../../globals/consts";
import { Logger } from "../../utils/logger";

export const tabNineProcess = new Binary();

Expand Down Expand Up @@ -134,7 +135,7 @@ export function deactivate(): Promise<unknown> {
return tabNineProcess.request({ Deactivate: {} });
}

console.error("No TabNine process");
Logger.error("No TabNine process");

return Promise.resolve(null);
}
Expand Down Expand Up @@ -170,7 +171,7 @@ export async function getCapabilities(): Promise<

return result;
} catch (error) {
console.error(error);
Logger.error(error);

return { enabled_features: [] };
}
Expand Down
9 changes: 5 additions & 4 deletions src/cloudEnvs/setupCloudState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { promises as fsPromises } from "fs";
import { ExtensionContext } from "vscode";
import * as consts from "./consts";
import { ensureExists, watch } from "../utils/file.utils";
import { Logger } from "../utils/logger";

export default async function state(context: ExtensionContext): Promise<void> {
await ensureExists(consts.TABNINE_CONFIG_DIR);
Expand All @@ -28,15 +29,15 @@ async function loadStateFromCloudEnv(context: ExtensionContext): Promise<void> {
await fsPromises
.writeFile(consts.TABNINE_TOKEN_FILE_PATH, tabnineToken)
.catch((e) => {
console.error("Error occurred while trying to load Tabnine token", e);
Logger.error("Error occurred while trying to load Tabnine token", e);
});
}

if (tabnineConfig)
await fsPromises
.writeFile(consts.TABNINE_CONFIG_FILE_PATH, tabnineConfig)
.catch((e) => {
console.error("Error occurred while trying to load Tabnine config", e);
Logger.error("Error occurred while trying to load Tabnine config", e);
});
}

Expand All @@ -59,7 +60,7 @@ function persistStateToCloudEnv(context: ExtensionContext): void {
)
)
.catch((e) => {
console.error(
Logger.error(
"Error occurred while trying to persist Tabnine token",
e
);
Expand All @@ -76,7 +77,7 @@ function persistStateToCloudEnv(context: ExtensionContext): void {
)
)
.catch((e) => {
console.error(
Logger.error(
"Error occurred while trying to persist Tabnine config",
e
);
Expand Down
6 changes: 4 additions & 2 deletions src/enterprise/statusBar/StatusBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
CONGRATS_MESSAGE_SHOWN_KEY,
} from "../../globals/consts";
import getUserInfo, { UserInfo } from "../requests/UserInfo";
import { Logger } from "../../utils/logger";

export class StatusBar implements Disposable {
private item: StatusItem;
Expand All @@ -40,7 +41,8 @@ export class StatusBar implements Disposable {
);
this.setDefaultStatus();

this.setServerRequired().catch(console.error);
// eslint-disable-next-line @typescript-eslint/unbound-method
this.setServerRequired().catch(Logger.error);
}

private async setServerRequired() {
Expand Down Expand Up @@ -81,7 +83,7 @@ export class StatusBar implements Disposable {
}

private setGenericError(error: Error) {
console.error(error);
Logger.error(error);
this.item.setError("Something went wrong");
this.item.setCommand(StatusState.OpenLogs);
}
Expand Down
3 changes: 2 additions & 1 deletion src/enterprise/update/serverUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
SELF_HOSTED_SERVER_CONFIGURATION,
TABNINE_HOST_CONFIGURATION,
} from "../consts";
import { Logger } from "../../utils/logger";

export default function serverUrl(): string | undefined {
const oldUrl = workspace
Expand All @@ -22,7 +23,7 @@ export function validateUrl(url: string | undefined): boolean {
Uri.parse(url || "", true);
return true;
} catch (error) {
console.error("Tabnine updater - wrong server url");
Logger.error("Tabnine updater - wrong server url");
return false;
}
}
2 changes: 1 addition & 1 deletion src/enterprise/update/updateAndReload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default async function updateAndReload(serverUrl: string) {
Logger.info("Tabnine updater - nothing to update");
}
} catch (e) {
console.error("Failed to update Tabnine plugin", e);
Logger.error("Failed to update Tabnine plugin");
void vscode.window
.showErrorMessage(
"Failed to update Tabnine, check Tabnine log output for more details",
Expand Down
3 changes: 2 additions & 1 deletion src/globals/proposedAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as vscode from "vscode";
import * as path from "path";
import * as os from "os";
import showMessage from "../preRelease/messages";
import { Logger } from "../utils/logger";

const EXTENSION_ID = "TabNine.tabnine-vscode";
const ARGV_FILE_NAME = "argv.json";
Expand All @@ -16,7 +17,7 @@ const ENABLE_PROPOSED_API = [

export default async function enableProposed(): Promise<boolean> {
return handleProposed().catch((error) => {
console.error("failed to enable proposedAPI", error);
Logger.error(`failed to enable proposedAPI ${error}`);
return false;
});
}
Expand Down
9 changes: 5 additions & 4 deletions src/handleUninstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as fs from "fs";
import * as path from "path";
import { Disposable } from "vscode";
import tabnineExtensionProperties from "./globals/tabnineExtensionProperties";
import { Logger } from "./utils/logger";

export default function handleUninstall(
onUninstall: () => Promise<unknown>
Expand All @@ -26,12 +27,12 @@ export default function handleUninstall(
if (isFileExists(curr) && isModified(curr, prev)) {
fs.readFile(uninstalledPath, (err, uninstalled) => {
if (err) {
console.error("failed to read .obsolete file:", err);
Logger.error("failed to read .obsolete file:", err);
throw err;
}
fs.readdir(extensionsPath, (error, files: string[]) => {
if (error) {
console.error(
Logger.error(
`failed to read ${extensionsPath} directory:`,
error
);
Expand All @@ -48,7 +49,7 @@ export default function handleUninstall(
fs.unwatchFile(uninstalledPath, watchFileHandler);
})
.catch((e) => {
console.error("failed to report uninstall:", e);
Logger.error("failed to report uninstall:", e);
});
}
});
Expand All @@ -60,7 +61,7 @@ export default function handleUninstall(
fs.watchFile(uninstalledPath, watchFileHandler)
);
} catch (error) {
console.error("failed to invoke uninstall:", error);
Logger.error("failed to invoke uninstall:", error);
}
return new Disposable(() => {});
}
3 changes: 2 additions & 1 deletion src/notificationsWidget/notificationsWidgetWebview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Capability } from "../capabilities/capabilities";
import { fireEvent } from "../binary/requests/requests";
import { StateType } from "../globals/consts";
import registerWidgetWebviewProvider from "../widgetWebview/widgetWebview";
import { Logger } from "../utils/logger";

const LOADED_NOTIFICATIONS_WIDGET = "loaded-notificaitons-widget-as-webview";

Expand All @@ -18,7 +19,7 @@ export default function registerNotificationsWebviewProvider(
onWebviewLoaded: () => {
void fireEvent({
name: LOADED_NOTIFICATIONS_WIDGET,
}).catch(console.error);
}).catch((e) => Logger.error(e));
},
});
}
3 changes: 2 additions & 1 deletion src/preRelease/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
} from "./versions";
import { ExtensionContext, GitHubReleaseResponse } from "./types";
import { Capability, isCapabilityEnabled } from "../capabilities/capabilities";
import { Logger } from "../utils/logger";

const badVersion = "9999.9999.9999";

Expand Down Expand Up @@ -50,7 +51,7 @@ export default async function handlePreReleaseChannels(
}
}
} catch (e) {
console.error(e);
Logger.error(e);
}
}

Expand Down
Loading

0 comments on commit 94cee5b

Please sign in to comment.