@@ -4,7 +4,7 @@ import { CreateTestRequestDto } from './dto/create-test-request.dto';
44import { IgnoreAreaDto } from './dto/ignore-area.dto' ;
55import { StaticService } from '../shared/static/static.service' ;
66import { PrismaService } from '../prisma/prisma.service' ;
7- import { Baseline , TestRun , TestStatus , TestVariation } from '@prisma/client' ;
7+ import { Baseline , Prisma , TestRun , TestStatus , TestVariation } from '@prisma/client' ;
88import { DiffResult } from './diffResult' ;
99import { EventsGateway } from '../shared/events/events.gateway' ;
1010import { TestRunResultDto } from '../test-runs/dto/testRunResult.dto' ;
@@ -244,16 +244,32 @@ export class TestRunsService {
244244 }
245245
246246 async delete ( id : string ) : Promise < TestRun > {
247+ this . logger . debug ( `Going to remove TestRun ${ id } ` ) ;
247248 const testRun = await this . findOne ( id ) ;
248249
250+ if ( ! testRun ) {
251+ this . logger . warn ( `TestRun not found ${ id } ` ) ;
252+ return ;
253+ }
254+
249255 await Promise . all ( [
250256 this . staticService . deleteImage ( testRun . diffName ) ,
251257 this . staticService . deleteImage ( testRun . imageName ) ,
252- this . prismaService . testRun . delete ( {
253- where : { id } ,
254- } ) ,
255258 ] ) ;
256259
260+ try {
261+ await this . prismaService . testRun . delete ( { where : { id } } ) ;
262+ } catch ( e ) {
263+ if ( e instanceof Prisma . PrismaClientKnownRequestError ) {
264+ // workaround https://github.com/Visual-Regression-Tracker/Visual-Regression-Tracker/issues/435
265+ if ( e . code === 'P2025' ) {
266+ this . logger . warn ( `TestRun already deleted ${ id } ` ) ;
267+ return ;
268+ }
269+ }
270+ }
271+
272+ this . logger . log ( `TestRun deleted ${ id } ` ) ;
257273 this . eventsGateway . testRunDeleted ( testRun ) ;
258274 return testRun ;
259275 }
0 commit comments