{"record":{"id":"4e211f54070ef88f","repo":"elsa-workflows/elsa-core","slug":"alterationfaultcodes-plannotfound-4e211f","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/GenerateAlterationJobs.cs","lineNumber":66,"sourceCode":"        if (workflowInstanceIds.Any())\n            await GenerateJobsAsync(context, plan, workflowInstanceIds);\n\n        context.SetResult(workflowInstanceIds.Count);\n    }\n\n    private async Task<AlterationPlan> GetPlanAsync(ActivityExecutionContext context)\n    {\n        var cancellationToken = context.CancellationToken;\n        var planId = context.Get(PlanId)!;\n        var alterationPlanStore = context.GetRequiredService<IAlterationPlanStore>();\n        var planFilter = new AlterationPlanFilter\n        {\n            Id = planId\n        };\n        var plan = await alterationPlanStore.FindAsync(planFilter, 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        return plan;\n    }\n\n    private async Task UpdatePlanStatusAsync(ActivityExecutionContext context, AlterationPlan plan)\n    {\n        var cancellationToken = context.CancellationToken;\n        var alterationPlanStore = context.GetRequiredService<IAlterationPlanStore>();\n        plan.Status = AlterationPlanStatus.Generating;\n        await alterationPlanStore.SaveAsync(plan, cancellationToken);\n    }\n\n    private async Task<IEnumerable<string>> FindMatchingWorkflowInstanceIdsAsync(ActivityExecutionContext context, AlterationWorkflowInstanceFilter filter)\n    {\n        var cancellationToken = context.CancellationToken;\n        var workflowInstanceFinder = context.GetRequiredService<IWorkflowInstanceFinder>();\n        return await workflowInstanceFinder.FindAsync(filter, cancellationToken);\n    }","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/elsa-workflows/elsa-core/blob/fe9217bdfa0e27f0e09e45006eb6898f616e513d/src/modules/Elsa.Alterations/Activities/GenerateAlterationJobs.cs#L48-L84","documentation":"The GenerateAlterations activity's GetPlanAsync looked up an AlterationPlan by ID via IAlterationPlanStore.FindAsync and found nothing. It then throws a FaultException with AlterationFaultCodes.PlanNotFound, which surfaces as a workflow fault rather than a plain exception. This guards the alteration pipeline against running with a missing or already-deleted plan.","triggerScenarios":"Calling GenerateAlterations (or otherwise executing GetPlanAsync) with a planId for which IAlterationPlanStore.FindAsync(planFilter) returns null — i.e., the ID does not exist in the plan store.","commonSituations":"Passing a hardcoded or copied plan ID that was never created; the plan was deleted by retention/cleanup before the workflow ran; using an ID from a different database/environment (staging vs production); a typo or GUID casing/whitespace issue in workflow input.","solutions":["Verify the planId exists before scheduling the workflow by querying the alteration plan store (or API) for that ID.","Check that the workflow is running against the same persistence store/environment where the plan was created.","Confirm the plan was not removed by cleanup or a prior workflow run; re-create it if needed.","Catch FaultException with code AlterationFaultCodes.PlanNotFound in the workflow's fault handler and surface a user-friendly message."],"exampleFix":"// before\nawait workflowInput.Set(\"PlanId\", copiedGuidString);\n\n// after\nvar plan = await alterationPlanStore.FindAsync(new AlterationPlanFilter { Id = planId });\nif (plan == null)\n    throw new InvalidOperationException($\"Plan {planId} does not exist; create it before running GenerateAlterations.\");","handlingStrategy":"validation","validationCode":"var plan = await alterationPlanStore.FindAsync(new AlterationPlanFilter { Id = planId });\nif (plan == null)\n    throw new InvalidOperationException($\"Plan {planId} not found; aborting before scheduling alteration workflow.\");","typeGuard":null,"tryCatchPattern":"try\n{\n    await generateAlterationsActivity.ExecuteAsync(context);\n}\ncatch (FaultException ex) when (ex.FaultCode == AlterationFaultCodes.PlanNotFound)\n{\n    logger.LogWarning(\"Alteration plan {PlanId} not found\", planId);\n}","preventionTips":["Always create the plan first and use the ID returned by the store, not a manually typed one.","Keep plans and workflows on the same environment/persistence store.","Add a pre-flight existence check when accepting plan IDs as workflow input."],"tags":["workflow","alterations","not-found","fault"],"backgroundTag":"entity-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"}