Refactor workspace migration runner exception handling (#17310)
# Introduction
In this PR we catch all the runner errors coming from a single workspace
migration action execution.
**1. `WorkspaceMigrationActionExecutionException`** (low-level,
action-specific)
- Thrown from action handlers, utils, and helper functions
- Contains specific error codes: `FIELD_METADATA_NOT_FOUND`,
`OBJECT_METADATA_NOT_FOUND`, `ENUM_OPERATION_FAILED`, `NOT_SUPPORTED`,
etc.
- Simple structure: `message`, `code`, `userFriendlyMessage`
- No action context - just describes what went wrong
**2. `WorkspaceMigrationRunnerException`** (high-level, runner-scoped)
- Only two codes: `INTERNAL_SERVER_ERROR` and `EXECUTION_FAILED`
- `EXECUTION_FAILED` **requires** `action` + `errors` (contains the
action context)
- `INTERNAL_SERVER_ERROR` **requires** `message` (no action context)
## Refactor
- Removed the `relatedFlatEntityMapsKeys` from the `WorkspaceMigration`
type as they're directly inferred from passed actions
- Swallowing actions rollbacks errors in order to iterate over all of
them
## Testing
Created a very straigthforward install application from workspace
migration endpoint in order to start testing the introduced
`WorkspaceMigrationActionExecutionException`
Introduced a feature flag that stop the access to the endpoint if not
enabled
Whole taken direction are totally subjective and highly prone to
mutations ( endpoint location, naming and input schema see
`ts-expect-error` comment )
cc @martmull
## Response error
```ts
{
"eventId": "evt_a1b2c3d4-5678-90ab-cdef-1234567890ab",
"extensions": {
"action": {
"metadataName": "fieldMetadata",
"type": "delete",
"universalIdentifier": "20202020-6110-4547-9fd0-2525257a2c3f"
},
"code": "APPLICATION_INSTALLATION_FAILED",
"errors": {
"metadata": {
"code": "ENTITY_NOT_FOUND",
"message": "Could not find flat entity with universal identifier 20202020-6110-4547-9fd0-2525257a2c3f"
},
"workspaceSchema": {
"code": "ENTITY_NOT_FOUND",
"message": "Could not find flat entity in maps"
}
},
"exceptionEventId": "exc_f9e8d7c6-5432-10ba-fedc-ba0987654321",
"userFriendlyMessage": "Migration execution failed."
},
"message": "Migration action 'delete' for 'fieldMetadata' failed",
"name": "GraphQLError"
}
```
This commit is contained in:
-8
@@ -1058,13 +1058,6 @@ export class WorkspaceMigrationBuildOrchestratorService {
|
||||
};
|
||||
}
|
||||
|
||||
const relatedFlatEntityMapsKeys = [
|
||||
...new Set([
|
||||
...Object.keys(fromToAllFlatEntityMaps),
|
||||
...Object.keys(dependencyAllFlatEntityMaps ?? {}),
|
||||
]),
|
||||
] as (keyof AllFlatEntityMaps)[];
|
||||
|
||||
const { aggregatedOrchestratorActionsReport } =
|
||||
aggregateOrchestratorActionsReport({
|
||||
orchestratorActionsReport,
|
||||
@@ -1075,7 +1068,6 @@ export class WorkspaceMigrationBuildOrchestratorService {
|
||||
return {
|
||||
status: 'success',
|
||||
workspaceMigration: {
|
||||
relatedFlatEntityMapsKeys,
|
||||
actions: [
|
||||
// Object and fields and indexes
|
||||
...aggregatedOrchestratorActionsReport.index.delete,
|
||||
|
||||
+3
-9
@@ -196,15 +196,9 @@ export class WorkspaceMigrationValidateBuildAndRunService {
|
||||
return;
|
||||
}
|
||||
|
||||
await this.workspaceMigrationRunnerService
|
||||
.run(validateAndBuildResult.workspaceMigration)
|
||||
.catch((error) => {
|
||||
this.logger.error(error);
|
||||
throw new WorkspaceMigrationV2Exception(
|
||||
WorkspaceMigrationV2ExceptionCode.RUNNER_INTERNAL_SERVER_ERROR,
|
||||
error.message,
|
||||
);
|
||||
});
|
||||
await this.workspaceMigrationRunnerService.run(
|
||||
validateAndBuildResult.workspaceMigration,
|
||||
);
|
||||
}
|
||||
|
||||
public async validateBuildAndRunWorkspaceMigration({
|
||||
|
||||
Reference in New Issue
Block a user