Skip to content

Commit 7cd1f06

Browse files
Samatladisgin
authored andcommitted
fix: reduce log spam with same error message to one message only
1 parent 66f460f commit 7cd1f06

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

DEVNOTE.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,11 @@ docker: Error response from daemon: error while mounting volume '': VolumeDriver
103103
Remove the following line in utbot_docker_dev.sh:
104104
```shell
105105
-v $MOUNT_LOCAL_NAME:/home/utbot/mnt \
106-
```
106+
```
107+
108+
### Problems with build in Visual Studio Code
109+
If you experience this error:
110+
```shell
111+
command npm run watch terminated with exit code 1
112+
```
113+
Then there is compilation error and if it is not fixed the previous version of the code will run (debugger won't work correctly)

vscode-plugin/src/client/client.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import { Protos } from '../requests/protos';
4242
import { Wrapper } from '../utils/utils';
4343
import { ClientEventsEmitter } from './clientEventsEmitter';
4444
import { ResponseHandler, SomeResponse } from '../responses/responseHandler';
45+
import { Status } from 'grpc/build/src/constants';
4546
const { logger, setupLogger } = ExtensionLogger;
4647

4748
type ResolveType<T> = (value: T | PromiseLike<T>) => void;
@@ -70,6 +71,7 @@ export class Client {
7071
}
7172

7273
private connectionStatus: ConnectionStatus = ConnectionStatus.INIT;
74+
private isNoConnectionEstablishedErrorLogged: boolean = true;
7375

7476
private _newClient = true;
7577
get newClient(): boolean {
@@ -117,12 +119,12 @@ export class Client {
117119
public setEventsHandlers(): void {
118120
this.events.onDidHeartbeatFailureEventEmitter.on(errorMessage => {
119121
if (!this.isConnectionBroken()) {
120-
const logMesage = this.isConnectionInInitState()
122+
const logMessage = this.isConnectionInInitState()
121123
? `Connection with server can't be established`
122124
: `Connection with server lost`;
123125
this.updateConnectionState(ConnectionStatus.BROKEN);
124126
messages.showErrorMessage(messages.serverIsDeadError);
125-
logger.warn(logMesage);
127+
logger.warn(logMessage);
126128
logger.debug(errorMessage);
127129
}
128130
});
@@ -207,7 +209,7 @@ export class Client {
207209
return new Promise<void>((resolve, reject) => {
208210
this.testsService.registerClient(registerClientRequest, (err) => {
209211
if (err) {
210-
reject(err.message);
212+
reject(err);
211213
} else {
212214
resolve();
213215
}
@@ -217,7 +219,16 @@ export class Client {
217219
this.metadata.add('clientId', clientId as string);
218220
resolve();
219221
}).then(undefined, err => {
220-
logger.error(err);
222+
let targetCode = Status.UNAVAILABLE;
223+
224+
if (err.code === targetCode) {
225+
if (this.isNoConnectionEstablishedErrorLogged) {
226+
this.isNoConnectionEstablishedErrorLogged = false;
227+
logger.error(err.message);
228+
}
229+
} else {
230+
logger.error(err.message);
231+
}
221232
resolve();
222233
});
223234
});
@@ -296,6 +307,10 @@ export class Client {
296307
}
297308

298309
private updateConnectionState(connectionStatus: ConnectionStatus): void {
310+
if (connectionStatus !== this.connectionStatus
311+
&& connectionStatus === ConnectionStatus.ESTABLISHED) {
312+
this.isNoConnectionEstablishedErrorLogged = true;
313+
}
299314
this.connectionStatus = connectionStatus;
300315
utbotUI.indicators().connectionStatusBarItem.text =
301316
this.getTitleByConnectionStatus(connectionStatus);

0 commit comments

Comments
 (0)