{"record":{"id":"639389c7e0b46f71","repo":"elsa-workflows/elsa-core","slug":"alterationfaultcodes-plannotfound","errorCode":"AlterationFaultCodes.PlanNotFound","errorMessage":"Alteration Plan with ID {planId} not found.","messagePattern":"Alteration Plan with ID (.+?) not found\\.","errorType":"error_code","errorClass":"FaultException","httpStatus":null,"severity":"error","filePath":"src/modules/Elsa.Alterations/Activities/CompleteAlterationPlan.cs","lineNumber":44,"sourceCode":"    public CompleteAlterationPlan([CallerFilePath] string? source = null, [CallerLineNumber] int? line = null) : base(source, line)\n    {\n    }\n\n    /// <summary>\n    /// The ID of the alteration plan.\n    /// </summary>\n    public Input<string> PlanId { get; set; } = null!;\n\n    /// <inheritdoc />\n    protected override async ValueTask ExecuteAsync(ActivityExecutionContext context)\n    {\n        var cancellationToken = context.CancellationToken;\n        var planId = context.Get(PlanId)!;\n        var manager = context.GetRequiredService<IAlterationPlanManager>();\n        var plan = await manager.GetPlanAsync(planId, cancellationToken);\n\n        if (plan == null)\n            throw new FaultException(AlterationFaultCodes.PlanNotFound, AlterationFaultCategories.Alteration, DefaultFaultTypes.System, $\"Alteration Plan with ID {planId} not found.\");\n\n        await manager.CompletePlanAsync(plan, cancellationToken);\n    }\n}","sourceCodeStart":26,"sourceCodeEnd":48,"githubUrl":"https://github.com/elsa-workflows/elsa-core/blob/fe9217bdfa0e27f0e09e45006eb6898f616e513d/src/modules/Elsa.Alterations/Activities/CompleteAlterationPlan.cs#L26-L48","documentation":"The CompleteAlterationPlan activity looks up the alteration plan by its PlanId input via IAlterationPlanManager.GetPlanAsync and throws a FaultException with code AlterationFaultCodes.PlanNotFound when no plan exists. This is a modeled workflow fault (category Alteration, type System) so the workflow can catch and compensate it rather than crashing the host.","triggerScenarios":"Executing a CompleteAlterationPlan activity whose PlanId input references an ID that does not exist (deleted plan, wrong ID input, plan stored in a different tenant/database).","commonSituations":"Plan ID passed via workflow input from an external system with a typo; plan deleted between dispatch and completion; multi-tenant deployment where the plan lives under another tenant.","solutions":["Verify the PlanId input value matches an existing alteration plan ID in the store.","Confirm the runtime is connected to the same tenant/database where the plan was created.","Add a fault handler for AlterationFaultCodes.PlanNotFound on the activity/workflow to fail gracefully.","Check that the plan was not deleted by a concurrent process before completion."],"exampleFix":"// before\ncontext.Set(PlanId, planIdFromExternalSystem);\n// (no check that planId exists)\n\n// after\nvar plan = await manager.GetPlanAsync(planIdFromExternalSystem, ct);\nif (plan == null)\n    throw new InvalidOperationException($\"Plan {planIdFromExternalSystem} does not exist; check the PlanId input.\");\ncontext.Set(PlanId, planIdFromExternalSystem);","handlingStrategy":"try-catch","validationCode":"var plan = await manager.GetPlanAsync(planId, ct);\nif (plan is null)\n    throw new InvalidOperationException($\"Plan '{planId}' not found; fix the PlanId input before running the workflow.\");","typeGuard":"bool PlanExists(IAlterationPlan? plan) => plan is not null;","tryCatchPattern":"try\n{\n    await workflow.RunAsync(instance, ct);\n}\ncatch (FaultException ex) when (ex.Code == AlterationFaultCodes.PlanNotFound)\n{\n    logger.LogError(\"Alteration plan not found: {Message}\", ex.Message);\n}","preventionTips":["Validate the PlanId input against the store before starting the workflow.","Register a workflow fault handler for AlterationFaultCodes.PlanNotFound.","Avoid hard-deleting plans that may still be referenced by running workflow instances."],"tags":["workflow-fault","alterations","resource-not-found"],"backgroundTag":"record-not-found","analyzedSha":"fe9217bdfa0e27f0e09e45006eb6898f616e513d","analyzedAt":"2026-09-13T20:32:34.702Z","contentChangedAt":"2026-09-13T20:32:34.702Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}