fix(server,cli): don't float promises (#4433)

* fix: don't allow floating promises

* fix: await all promises

* fix: download archives

* fix cli tests

* fix: skip web
This commit is contained in:
Jonathan Jogenfors
2023-10-13 07:22:40 +02:00
committed by GitHub
parent 7e9fc4aa97
commit f0bb50b61a
13 changed files with 41 additions and 43 deletions

View File

@@ -18,6 +18,7 @@ module.exports = {
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-floating-promises': 'error',
'prettier/prettier': 0,
},
};

View File

@@ -272,7 +272,7 @@ export class AssetService {
zip.addFile(originalPath, filename);
}
zip.finalize();
void zip.finalize();
return { stream: zip.stream };
}

View File

@@ -267,9 +267,9 @@ describe(SearchService.name, () => {
});
describe('handleIndexAlbums', () => {
it('should skip if search is disabled', () => {
it('should skip if search is disabled', async () => {
sut['enabled'] = false;
sut.handleIndexAlbums();
await sut.handleIndexAlbums();
});
it('should index all the albums', async () => {
@@ -355,18 +355,18 @@ describe(SearchService.name, () => {
});
describe('handleIndexAsset', () => {
it('should skip if search is disabled', () => {
it('should skip if search is disabled', async () => {
sut['enabled'] = false;
sut.handleIndexFace({ assetId: 'asset-1', personId: 'person-1' });
await sut.handleIndexFace({ assetId: 'asset-1', personId: 'person-1' });
expect(searchMock.importFaces).not.toHaveBeenCalled();
expect(personMock.getFacesByIds).not.toHaveBeenCalled();
});
it('should index the face', () => {
it('should index the face', async () => {
personMock.getFacesByIds.mockResolvedValue([faceStub.face1]);
sut.handleIndexFace({ assetId: 'asset-1', personId: 'person-1' });
await sut.handleIndexFace({ assetId: 'asset-1', personId: 'person-1' });
expect(personMock.getFacesByIds).toHaveBeenCalledWith([{ assetId: 'asset-1', personId: 'person-1' }]);
});

View File

@@ -75,7 +75,7 @@ export class AppModule implements OnModuleInit, OnModuleDestroy {
await this.appService.init();
}
onModuleDestroy() {
this.appService.destroy();
async onModuleDestroy() {
await this.appService.destroy();
}
}

View File

@@ -16,7 +16,7 @@ export class CommunicationRepository implements OnGatewayConnection, OnGatewayDi
this.logger.log(`New websocket connection: ${client.id}`);
const user = await this.authService.validate(client.request.headers, {});
if (user) {
client.join(user.id);
await client.join(user.id);
this.send(CommunicationEvent.SERVER_VERSION, user.id, serverVersion);
} else {
client.emit('error', 'unauthorized');
@@ -28,8 +28,8 @@ export class CommunicationRepository implements OnGatewayConnection, OnGatewayDi
}
}
handleDisconnect(client: Socket) {
client.leave(client.nsp.name);
async handleDisconnect(client: Socket) {
await client.leave(client.nsp.name);
this.logger.log(`Client ${client.id} disconnected from Websocket`);
}

View File

@@ -24,4 +24,4 @@ function bootstrap() {
process.exit(1);
}
}
bootstrap();
void bootstrap();

View File

@@ -90,14 +90,14 @@ export class AppService {
[JobName.LIBRARY_QUEUE_CLEANUP]: () => this.libraryService.handleQueueCleanup(),
});
process.on('uncaughtException', (error: Error | any) => {
process.on('uncaughtException', async (error: Error | any) => {
const isCsvError = error.code === 'CSV_RECORD_INCONSISTENT_FIELDS_LENGTH';
if (!isCsvError) {
throw error;
}
this.logger.warn('Geocoding csv parse error, trying again without cache...');
this.metadataService.init(true);
await this.metadataService.init(true);
});
await this.metadataService.init();