{"record":{"id":"2d4ffbaf5a6598a5","repo":"nocobase/nocobase","slug":"docker-instance-id-generation-did-not-return-an-in","errorCode":null,"errorMessage":"Docker instance ID generation did not return an instance ID.","messagePattern":"Docker instance ID generation did not return an instance ID\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/cli/src/commands/license/shared.ts","lineNumber":272,"sourceCode":"\nexport async function generateValidatedInstanceIdFromEnvVars(envVars: Record<string, string>): Promise<string> {\n  await validateLicenseDbConnectionFromEnvVars(envVars);\n  return await generateInstanceIdFromEnvVars(envVars);\n}\n\nasync function generateInstanceIdForDockerRuntime(\n  runtime: Extract<ManagedAppRuntime, { kind: 'docker' }>,\n): Promise<string> {\n  const envVars = await buildRuntimeEnvVars(runtime);\n  const payload = (await runDockerLicenseJsonCommand(runtime, [\n    'license',\n    'generate-id',\n    ...buildDockerLicenseDbFlagArgs(envVars),\n  ])) as { instanceId?: unknown };\n\n  const instanceId = trimValue(payload.instanceId);\n  if (!instanceId) {\n    throw new Error('Docker instance ID generation did not return an instance ID.');\n  }\n  return instanceId;\n}\n\nexport async function generateInstanceIdForRuntime(runtime: ManagedAppRuntime): Promise<string> {\n  if (runtime.kind === 'docker') {\n    return await generateInstanceIdForDockerRuntime(runtime);\n  }\n\n  if (runtime.kind === 'local') {\n    return await generateValidatedInstanceIdFromEnvVars(await buildRuntimeEnvVars(runtime));\n  }\n\n  throw new Error(`Env \"${runtime.envName}\" does not support automatic instance ID generation.`);\n}\n\nexport async function saveInstanceId(runtime: ManagedAppRuntime, instanceId: string): Promise<string> {\n  const normalized = String(instanceId ?? '').trim();","sourceCodeStart":254,"sourceCodeEnd":290,"githubUrl":"https://github.com/nocobase/nocobase/blob/fa42722fefe44265490dff2c27d79e2882bce4fa/packages/core/cli/src/commands/license/shared.ts#L254-L290","documentation":"For docker runtimes the CLI runs `docker run ... nb license generate-id --json` and expects a JSON object with an instanceId field. If the parsed payload lacks instanceId or it trims to empty, this error is thrown — the container responded successfully but did not produce the expected value.","triggerScenarios":"The container's generate-id command returns JSON without instanceId (e.g. an error payload like {\"error\":\"...\"} still parses as JSON), or instanceId is null/empty because the DB flags passed via --db-* were incomplete or wrong inside the container.","commonSituations":"Env for the docker runtime missing DB_* vars so the container-side generation silently fails; image version that returns a different JSON shape; container-side DB validation failing but reported as JSON without instanceId.","solutions":["Inspect the full parsed payload by running the docker command manually — the JSON likely contains an error field explaining why instanceId is absent","Ensure the docker runtime env has complete DB_DIALECT/DB_HOST/DB_PORT/DB_DATABASE/DB_USER/DB_PASSWORD values","Verify the container can reach the DB over the docker network (runtime.dockerNetworkName)","Update CLI and docker image to matching versions","If the payload shape changed, report/upgrade — older images may not return instanceId"],"exampleFix":"// before\nDB_DIALECT=\nDB_HOST=\n// after (in the docker runtime env)\nDB_DIALECT=postgres\nDB_HOST=host.docker.internal\nDB_PORT=5432\nDB_DATABASE=nocobase\nDB_USER=nocobase\nDB_PASSWORD=secret","handlingStrategy":"type-guard","validationCode":"const envVars = await buildRuntimeEnvVars(runtime);\nconst dbKeys = ['DB_DIALECT','DB_HOST','DB_PORT','DB_DATABASE','DB_USER','DB_PASSWORD'];\nconst missing = dbKeys.filter((k) => !String(envVars[k] ?? '').trim());\nif (missing.length) throw new Error(`Docker runtime env missing: ${missing.join(', ')}`);","typeGuard":"function hasInstanceId(payload: unknown): payload is { instanceId: string } {\n  return typeof payload === 'object' && payload !== null && 'instanceId' in payload && String((payload as any).instanceId ?? '').trim() !== '';\n}","tryCatchPattern":"try {\n  const id = await generateInstanceIdForRuntime(runtime);\n} catch (e) {\n  if (e.message.includes('did not return an instance ID')) {\n    // container returned JSON without instanceId — inspect payload/error field via manual docker run\n  }\n  throw e;\n}","preventionTips":["Ensure the docker runtime env carries all DB_* vars","Confirm container-to-DB reachability over the docker network","Keep image and CLI versions matched","Manually run the generate-id docker command after image changes"],"tags":["docker","license","instance-id","json"],"backgroundTag":"missing-response-field","analyzedSha":"fa42722fefe44265490dff2c27d79e2882bce4fa","analyzedAt":"2026-09-01T00:54:31.202Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}