{"record":{"id":"b842ea4a6d80a9d4","repo":"langgenius/dify","slug":"missing-required-deployment-environment-variable","errorCode":null,"errorMessage":"Missing required deployment environment variable.","messagePattern":"Missing required deployment environment variable\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"web/features/deployments/create-guide/state/submission.ts","lineNumber":172,"sourceCode":"\n      set(isCreatingDeploymentAtom, true)\n\n      try {\n        const selectedEnvironmentIdentifier = selectedEnvironmentId.trim()\n        const freshSelectedEnvironment =\n          selectedEnvironment ||\n          (selectedEnvironmentIdentifier\n            ? (await deployableEnvironmentsQuery.refetch()).data?.environments.find((environment) =>\n                environmentMatchesIdentifier(environment, selectedEnvironmentIdentifier),\n              )\n            : undefined)\n        const targetEnvironmentId = freshSelectedEnvironment?.id\n        if (!targetEnvironmentId)\n          throw new CreateDeploymentGuideSubmissionBlockedError('deployFailed')\n\n        if (!get(requiredBindingsReadyAtom)) throw new Error('Missing required deployment binding.')\n        if (!get(requiredEnvVarsReadyAtom))\n          throw new Error('Missing required deployment environment variable.')\n\n        const envVars = envVarSlots.flatMap((slot) => envVarInput(slot, envVarValues[slot.key]))\n        const commonDeploymentRequest = {\n          newAppInstance: {\n            displayName: submittedInstanceName,\n            description: get(instanceDescriptionAtom).trim() || undefined,\n          },\n          environmentId: targetEnvironmentId,\n          releaseName: submittedReleaseName,\n          releaseDescription: submittedReleaseDescription || undefined,\n          credentials: selectedDeploymentRuntimeCredentials(bindingSlots, bindingSelections),\n          envVars,\n          idempotencyKey: createDeploymentIdempotencyKey(),\n          expectedDslDigest: deploymentOptions?.dslDigest,\n        } satisfies Omit<DeployRequest, 'dsl' | 'sourceAppId'>\n        const deploymentRequest =\n          method === 'importDsl'\n            ? {","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/web/features/deployments/create-guide/state/submission.ts#L154-L190","documentation":"Thrown as a plain Error when requiredEnvVarsReadyAtom is false at submission time, immediately after the binding readiness check. Like error 161, it is a state-invariant violation indicating the submission path was reached despite required environment variables not being fully filled. envVarSlots each contribute required values that must be present in envVarValues.","triggerScenarios":"Fires when one or more envVarSlots marked required have empty/invalid values in envVarValues at submit time, so requiredEnvVarsReadyAtom resolves false.","commonSituations":"A required env var slot was added but not filled, a value was cleared by the user after the gate check, or the derived readiness atom does not recompute because the input atom reference did not change.","solutions":["Ensure canDeployAtom includes get(requiredEnvVarsReadyAtom) so submission is blocked upstream.","Inspect envVarSlots and envVarValues in DevTools to identify the unfilled required slot.","Render per-field validation messages tied to the same readiness derivation the gate uses.","Verify envVarValues updates produce new object references so Jotai recomputes derived atoms."],"exampleFix":"// before\nif (!get(requiredEnvVarsReadyAtom))\n  throw new Error('Missing required deployment environment variable.')\n\n// after - surface which slot is missing\nconst missingEnvVars = envVarSlots.filter((slot) => slot.required && !envVarValues[slot.key])\nif (missingEnvVars.length) {\n  set(submissionErrorAtom, { kind: 'missing-env-vars', slots: missingEnvVars })\n  return undefined\n}","handlingStrategy":"validation","validationCode":"// Pre-check env vars readiness before allowing submit\nconst envVarsReady = useAtomValue(requiredEnvVarsReadyAtom)\nconst canSubmit = environmentSelected && bindingsReady && envVarsReady","typeGuard":"function areEnvVarsReady(slots: EnvVarSlot[], values: Record<string, string>): boolean {\n  return slots.filter((s) => s.required).every((s) => values[s.key]?.trim())\n}","tryCatchPattern":"try {\n  await submit()\n} catch (e) {\n  if (e instanceof Error && e.message === 'Missing required deployment environment variable.') {\n    setEnvVarError('Please fill all required environment variables.')\n    return\n  }\n  throw e\n}","preventionTips":["Include requiredEnvVarsReadyAtom in the canDeployAtom conjunction.","Validate each required env var on blur and show inline errors.","Ensure envVarValues atom emits new references on change so derived atoms recompute.","Test that submit is blocked when any required env var slot is empty."],"tags":["frontend","deployment","state-management","jotai","invariant-violation","env-vars"],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}