Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion services/workflows-service/prisma/data-migrations
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import { CollectionFlowStateService } from './services/collection-flow-state.ser
import { CollectionFlowDocumentsController } from './controllers/collection-flow.documents.controller';
import { CollectionFlowDocumentsService } from './services/collection-flow-documents.service';
import { DocumentFileModule } from '@/document-file/document-file.module';
import { CollectionFlowUtilityModule } from './services/сollection-flow-utility/collection-flow-utility.module';

@Module({
imports: [
Expand All @@ -67,6 +68,7 @@ import { DocumentFileModule } from '@/document-file/document-file.module';
forwardRef(() => WorkflowModule),
DocumentModule,
DocumentFileModule,
CollectionFlowUtilityModule,
],
controllers: [
CollectionFlowController,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
DocumentStatus,
EndUserVariant,
UiDefinition,
WorkflowRuntimeData,
} from '@prisma/client';
import { findEntityFieldsDefinition } from '../helpers/find-entity-fields-definition';
import { findDocumentDefinitionByTypeAndCategory } from '../helpers/find-document-definition-by-type-and-category';
Expand All @@ -38,6 +37,7 @@ import {
} from '@/prisma/prisma.util';
import { PrismaService } from '@/prisma/prisma.service';
import { assertIsValidProjectIds } from '@/project/project-scope.service';
import { CollectionFlowUtilityService } from './сollection-flow-utility/collection-flow-utility.service';

@Injectable()
export class CollectionFlowStateService {
Expand All @@ -49,6 +49,7 @@ export class CollectionFlowStateService {
protected readonly workflowService: WorkflowService,
protected readonly appLogger: AppLoggerService,
protected readonly prismaService: PrismaService,
protected readonly collectionFlowUtilityService: CollectionFlowUtilityService,
) {}

async getCollectionFlowState(workflowId: string, projectIds: TProjectIds) {
Expand All @@ -60,6 +61,15 @@ export class CollectionFlowStateService {
);

const collectionFlowState = getCollectionFlowState(workflowWithRelations.context);
const isCollectionFlowStateSupported =
await this.collectionFlowUtilityService.isCollectionFlowStateSupported(
workflowId,
projectIds,
);

if (!isCollectionFlowStateSupported) {
return null;
}

if (!collectionFlowState) {
throw new CollectionFlowMissingException();
Expand Down Expand Up @@ -281,41 +291,6 @@ export class CollectionFlowStateService {
return collectionFlowState.status;
}

private getEntityIdsFromWorkflow(
workflow: WorkflowRuntimeData & {
childWorkflowsRuntimeData: WorkflowRuntimeData[];
},
): Array<{ entityId: string; entityType: TEntityType }> {
const entityIds: Array<{ entityId: string; entityType: TEntityType }> = [
{
entityId: workflow.context.entity.ballerineEntityId,
entityType: EntityType.business,
},
];

workflow.childWorkflowsRuntimeData?.forEach(childWorkflow => {
if (!childWorkflow.endUserId) {
throw new Error('End user ID not found on child workflow.');
}

entityIds.push({
entityId: childWorkflow.endUserId,
entityType: EntityType.ubo,
});
});

workflow.context?.entity?.data?.additionalInfo?.directors?.forEach(
(director: { ballerineEntityId: string }) => {
entityIds.push({
entityId: director.ballerineEntityId,
entityType: EntityType.director,
});
},
);

return entityIds;
}

async updateCollectionFlowState(
workflowId: string,
newState: UpdateCollectionFlowStateDto,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// eslint-disable-next-line import/no-cycle
import { WorkflowModule } from '@/workflow/workflow.module';
import { forwardRef, Module } from '@nestjs/common';
import { CollectionFlowUtilityService } from './collection-flow-utility.service';
import { UiDefinitionModule } from '@/ui-definition/ui-definition.module';

@Module({
imports: [
// eslint-disable-next-line import/no-cycle
forwardRef(() => WorkflowModule),
UiDefinitionModule,
],
providers: [CollectionFlowUtilityService],
exports: [CollectionFlowUtilityService],
})
export class CollectionFlowUtilityModule {}
Comment on lines +1 to +16
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Critical: Fix directory name with Cyrillic character.

The directory name contains a Cyrillic 'с' instead of Latin 'c' in "сollection-flow-utility". This can cause serious issues with:

  • File system operations on different OS
  • Git operations and version control
  • Developer tools and IDEs
  • Build processes

Rename the directory from сollection-flow-utility to collection-flow-utility (using Latin 'c').

The module structure itself is correct with proper handling of circular dependencies using forwardRef.

🤖 Prompt for AI Agents
In
services/workflows-service/src/collection-flow/services/сollection-flow-utility/collection-flow-utility.module.ts
lines 1 to 16, the directory name "сollection-flow-utility" uses a Cyrillic 'с'
instead of a Latin 'c', which can cause cross-platform and tooling issues.
Rename the directory to use the Latin 'c' as "collection-flow-utility" and
update all related import paths accordingly to ensure consistency and avoid
errors.

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { isPrismaException } from '@/common/is-prisma-exception/is-prisma-exception';
import { TProjectIds } from '@/types';
import { UiDefinitionService } from '@/ui-definition/ui-definition.service';
import { WorkflowService } from '@/workflow/workflow.service';
import { forwardRef, Inject, Injectable } from '@nestjs/common';

@Injectable()
export class CollectionFlowUtilityService {
constructor(
@Inject(forwardRef(() => WorkflowService))
protected readonly workflowService: WorkflowService,
protected readonly uiDefinitionService: UiDefinitionService,
) {}

async isCollectionFlowStateSupported(workflowId: string, projectIds: TProjectIds) {
const workflowDefinition = await this.workflowService.getWorkflowByIdWithRelations(
workflowId,
projectIds,
);

try {
await this.uiDefinitionService.getByWorkflowDefinitionId(
workflowDefinition.workflowDefinitionId,
'collection_flow',
projectIds,
);

return true;
} catch (error) {
if (isPrismaException(error) && error.code === 'P2025') {
return false;
}

throw error;
}
}
}
Comment on lines +1 to +37
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Critical: Fix directory name with Cyrillic character.

Same issue as the module file - the directory name contains a Cyrillic 'с' instead of Latin 'c' in "сollection-flow-utility".

Rename the directory from сollection-flow-utility to collection-flow-utility (using Latin 'c').

🤖 Prompt for AI Agents
In
services/workflows-service/src/collection-flow/services/сollection-flow-utility/collection-flow-utility.service.ts
lines 1 to 37, the directory name "сollection-flow-utility" contains a Cyrillic
'с' instead of a Latin 'c'. Rename the directory to "collection-flow-utility"
using the Latin 'c' to fix the character encoding issue and ensure proper module
resolution.

Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
import { isType } from '@ballerine/common';
import { PrismaClientKnownRequestError } from '@prisma/client/runtime';
import { z } from 'zod';

const ALL_PRISMA_ERROR_CODES = [
// Authentication failed
'P1000',
// Unable to connect to database
'P1001',
// Database server connection timed out
'P1002',
// Database does not exist
'P1003',
// Operations timed out
'P1008',
// Database already exists
'P1009',
// User access denied
'P1010',
// Error starting transaction
'P1011',
// Validation error
'P1012',
// Preview feature not enabled
'P1013',
// Underlying kind mismatch
'P1014',
// Prisma extension error
'P1015',
// Engine data loading error
'P1016',
// Server closed connection
'P1017',

// Query Engine (P2xxx) - Query execution and data validation errors
// Input value too long
'P2000',
// Record does not exist
'P2001',
// Unique constraint violation
'P2002',
// Foreign key constraint violation
'P2003',
// Constraint violation
'P2004',
// Value invalid for type
'P2005',
// Field value null violation
'P2006',
// Data validation error
'P2007',
// Failed to parse query
'P2008',
// Failed to validate query
'P2009',
// Raw query error
'P2010',
// Null constraint violation
'P2011',
// Missing required value
'P2012',
// Missing required argument
'P2013',
// Change violates relation
'P2014',
// Related record not found
'P2015',
// Query interpretation error
'P2016',
// Records not connected
'P2017',
// Required connected records not found
'P2018',
// Input error
'P2019',
// Value out of range
'P2020',
// Table does not exist
'P2021',
// Column does not exist
'P2022',
// Inconsistent column data
'P2023',
// Query execution timed out
'P2024',
// Operation failed
'P2025',
// Unsupported feature
'P2026',
// Multiple errors
'P2027',
// Transaction API error
'P2028',
// Query batch error
'P2029',
// Explicit transaction required
'P2030',
// Transaction rolled back
'P2031',
// Number out of range
'P2033',
// Transaction timeout
'P2034',
// Invalid transaction state
'P2035',
// Transaction rollback error
'P2036',
// Transaction commit error
'P2037',

// Schema Engine (P3xxx) - Schema and migration errors
// Failed to create database
'P3000',
// Migration possible data loss
'P3001',
// Migration required
'P3002',
// Migration format error
'P3003',
// Migration create error
'P3004',
// Migration apply error
'P3005',
// Migration name required
'P3006',
// Migration already exists
'P3007',
// Migration not found
'P3008',
// Migrate command error
'P3009',
// Migration squash error
'P3010',
// Migration rolled back
'P3011',
// Missing migration file
'P3012',
// Conflicting migrations
'P3013',
// Migrations list error
'P3014',
// Could not find migration
'P3015',
// Migration verification error
'P3016',
// Migration execution error
'P3017',
// Migration manifest error
'P3018',
// Migration script error
'P3019',
// Migration history error
'P3020',
// Migration history conflict
'P3021',
// Failed to parse schema
'P3022',

// DB Pull (P4xxx) - Database introspection errors
// Introspection error
'P4000',
// Detection conflict
'P4001',
// Introspection validation error
'P4002',

// Accelerate (P5xxx/P6xxx) - Performance and optimization errors
// Invalid connection string
'P5011',
// Engine version mismatch
'P6000',
// Migration pending
'P6001',
// Engine not started
'P6002',
// Engine timeout
'P6003',
// Engine crashed
'P6004',
// Engine not found
'P6005',
// Engine start error
'P6006',
// Engine protocol error
'P6008',
// Engine file error
'P6009',
// Engine binary error
'P6010'
] as const;
Comment on lines +5 to +190
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Comprehensive error code coverage looks good.

The list of Prisma error codes is well-organized and categorized. The comments provide clear context for each category of errors, making the code maintainable and understandable.

However, let's verify that this list includes all current Prisma error codes:


🌐 Web query:

What are all the official Prisma error codes as of 2024? Please provide a comprehensive list including P1xxx, P2xxx, P3xxx, P4xxx, P5xxx, and P6xxx categories.

💡 Result:

As of 2024, Prisma defines a comprehensive set of error codes to help developers diagnose and resolve issues effectively. These error codes are categorized as follows:

Common Errors:

  • P1000: Authentication failed against the database server.
  • P1001: Can't reach the database server at the specified host and port.
  • P1002: Connection to the database server timed out.
  • P1003: Database does not exist at the specified path or server.
  • P1008: Operation timed out after a specified duration.
  • P1009: Database already exists on the server.
  • P1010: User was denied access to the database.
  • P1011: Error opening a TLS connection.
  • P1012: Schema validation error.
  • P1013: Invalid database connection string.
  • P1014: Underlying model for a specified model does not exist.
  • P1015: Unsupported database version.
  • P1016: Incorrect parameters provided.
  • P1017: Server has closed the connection.

Prisma Client (Query Engine) Errors:

  • P2000: Provided value for the column is too long.
  • P2001: Record searched for does not exist.
  • P2002: Unique constraint failed.
  • P2003: Foreign key constraint failed.
  • P2004: A constraint failed on the database.
  • P2005: Stored value is invalid for the field's type.
  • P2006: Provided value for the field is not valid.
  • P2007: Data validation error.
  • P2008: Failed to parse the query.
  • P2009: Failed to validate the query.
  • P2010: Raw query failed.
  • P2011: Null constraint violation.
  • P2012: Missing a required value.
  • P2013: Missing a required argument.
  • P2014: Change would violate the required relation.
  • P2015: Related record could not be found.
  • P2016: Query interpretation error.
  • P2017: Records for relation are not connected.
  • P2018: Required connected records were not found.
  • P2019: Input error.
  • P2020: Value out of range for the type.
  • P2021: Table does not exist in the current database.
  • P2022: Column does not exist in the current database.
  • P2023: Inconsistent column data.
  • P2024: Timed out fetching a new connection from the pool.
  • P2025: Operation failed because it depends on one or more records that were required but not found.
  • P2026: Current database provider doesn't support a feature that the query used.
  • P2027: Multiple errors occurred on the database during query execution.
  • P2028: Transaction API error.
  • P2030: Cannot find a fulltext index to use for the search.
  • P2031: Prisma needs to perform transactions, which requires your MongoDB server to be run as a replica set.
  • P2033: Number used in the query does not fit into a 64-bit signed integer.
  • P2034: Transaction failed due to a write conflict or a deadlock.
  • P2035: Assertion violation on the database.
  • P2036: Error in external connector.
  • P2037: Too many database connections opened.

Prisma Migrate (Schema Engine) Errors:

  • P3000: Failed to create database.
  • P3001: Migration possible with destructive changes and possible data loss.
  • P3002: The attempted migration was rolled back.
  • P3003: The format of migrations changed; saved migrations are no longer valid.
  • P3004: The database is a system database; it should not be altered with Prisma Migrate.
  • P3005: The database schema is not empty.
  • P3006: Migration failed to apply cleanly to the shadow database.
  • P3007: Some of the requested preview features are not yet allowed in schema engine.
  • P3008: The migration is already recorded as applied in the database.
  • P3009: Found failed migrations in the target database; new migrations will not be applied.
  • P3010: The name of the migration is too long.
  • P3011: Migration cannot be rolled back because it was never applied to the database.
  • P3012: Migration cannot be rolled back because it is not in a failed state.
  • P3013: Datasource provider arrays are no longer supported in migrate.
  • P3014: Prisma Migrate could not create the shadow database.
  • P3015: Could not find the migration file.
  • P3016: The fallback method for database resets failed.
  • P3017: The migration could not be found.
  • P3018: A migration failed to apply.
  • P3019: The datasource provider specified in your schema does not match the one specified in the migration lock.
  • P3020: The automatic creation of shadow databases is disabled on Azure SQL.
  • P3021: Foreign keys cannot be created on this database.
  • P3022: Direct execution of DDL SQL statements is disabled on this database.

Prisma Accelerate Errors:

  • P6000: Generic error to catch all other errors.
  • P6001: The URL is malformed; for instance, it does not use the prisma:// protocol.
  • P6002: The API Key in the connection string is invalid.
  • P6003: The included usage of the current plan has been exceeded.
  • P6004: The global timeout of Accelerate has been exceeded.
  • P6005: The user supplied invalid parameters.
  • P6006: The chosen Prisma version is not compatible with Accelerate.
  • P6008: The engine failed to start.
  • P6009: The global response size limit of Accelerate has been exceeded.
  • P6010: Your Accelerate project is disabled.
  • P5011: This error indicates that the request volume exceeded.

For a detailed explanation of each error code, refer to the Prisma Documentation.


Synchronize Prisma error code comments with official documentation

The list covers all current Prisma error codes, but many comment descriptions are outdated or inaccurate. Please update the in-code comments to match the official Prisma v4 error reference.

Affected locations (services/workflows-service/src/common/is-prisma-exception/is-prisma-exception.ts, lines 5–190):

  • Common Errors (P1011–P1017): replace generic/mismatched comments (e.g. P1011 “Error starting transaction”) with the exact descriptions from https://www.prisma.io/docs/orm/reference/error-reference
  • Query Engine Errors:
    • P2024, P2025, P2026, P2027: expand to full official wording
    • P2029: confirm or remove (not listed in the 2024 docs)
    • P2030–P2037: update all comments to the official definitions
  • (Optional) Migrate (P3000–P3022), DB Pull (P4000–P4002), and Accelerate (P5011, P6000–P6010) comments should likewise be aligned with the docs

Example diff:

-  'P1011', // Error starting transaction
+  'P1011', // Error opening a TLS connection

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In
services/workflows-service/src/common/is-prisma-exception/is-prisma-exception.ts
between lines 5 and 190, the comments describing Prisma error codes are outdated
or inaccurate. Update all comment descriptions for error codes P1011 to P1017,
P2024 to P2027, P2030 to P2037, and optionally P3000 to P3022, P4000 to P4002,
and P5011, P6000 to P6010 to exactly match the official Prisma v4 error
reference documentation at
https://www.prisma.io/docs/orm/reference/error-reference. Remove or confirm the
presence of P2029 if it is not listed in the official docs. Replace generic or
mismatched comments with the precise official wording for each error code.


export const isPrismaException = (value: unknown): value is PrismaClientKnownRequestError =>
isType(z.object({ code: z.enum(ALL_PRISMA_ERROR_CODES) }))(value);
2 changes: 2 additions & 0 deletions services/workflows-service/src/document/document.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { WorkflowModule } from '@/workflow/workflow.module';
import { UiDefinitionModule } from '@/ui-definition/ui-definition.module';
import { WorkflowDefinitionModule } from '@/workflow-defintion/workflow-definition.module';
import { ProjectScopeService } from '@/project/project-scope.service';
import { CollectionFlowUtilityModule } from '@/collection-flow/services/сollection-flow-utility/collection-flow-utility.module';

@Module({
imports: [
Expand All @@ -19,6 +20,7 @@ import { ProjectScopeService } from '@/project/project-scope.service';
forwardRef(() => WorkflowModule),
UiDefinitionModule,
WorkflowDefinitionModule,
CollectionFlowUtilityModule,
],
controllers: [DocumentControllerExternal],
providers: [DocumentService, DocumentRepository, ProjectScopeService],
Expand Down
Loading
Loading