{"record":{"id":"0002313aacec8027","repo":"coleam00/Archon","slug":"warning-data-is-not-valid-json-event-will-be","errorCode":null,"errorMessage":"Warning: --data is not valid JSON — event will be emitted without data payload: ${rawData}","messagePattern":"Warning: --data is not valid JSON — event will be emitted without data payload: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/cli/src/cli.ts","lineNumber":1054,"sourceCode":"                jsonFlag,\n                'Usage: archon workflow event emit --run-id <run-id> --type <event-type>\\n' +\n                  'Error: --type is required'\n              );\n            }\n            if (!isValidEventType(eventType)) {\n              const { WORKFLOW_EVENT_TYPES } = await import('@archon/workflows/store');\n              return await fail(\n                jsonFlag,\n                `Error: unknown event type: ${eventType}\\nValid types: ${WORKFLOW_EVENT_TYPES.join(', ')}`\n              );\n            }\n            let eventData: Record<string, unknown> | undefined;\n            const rawData = values.data as string | undefined;\n            if (rawData) {\n              try {\n                eventData = JSON.parse(rawData) as Record<string, unknown>;\n              } catch {\n                console.warn(\n                  `Warning: --data is not valid JSON — event will be emitted without data payload: ${rawData}`\n                );\n              }\n            }\n            await workflowEventEmitCommand(runId, eventType, eventData, effectiveCwd);\n            break;\n          }\n\n          case 'install': {\n            const installSlug = positionals[2];\n            if (!installSlug) {\n              return await fail(jsonFlag, 'Usage: archon workflow install <slug> [--force]');\n            }\n            const forceFlag = values.force as boolean | undefined;\n            await workflowInstallCommand(installSlug, effectiveCwd, forceFlag);\n            break;\n          }\n","sourceCodeStart":1036,"sourceCodeEnd":1072,"githubUrl":"https://github.com/coleam00/Archon/blob/0773b9745896ef0612e709c80845a0f7db315b19/packages/cli/src/cli.ts#L1036-L1072","documentation":"The archon CLI 'workflow event emit' command (packages/cli/src/cli.ts:1054) parses the --data flag as JSON. When parsing fails it does not abort: it prints this warning and emits the event with no data payload (eventData stays undefined), so downstream nodes waiting on the event receive an empty data object.","triggerScenarios":"Running a CLI command like `archon workflow event emit <runId> <eventType> --data '...'` where the --data value is not valid JSON — unquoted shell values, keys without quotes, single quotes inside the value, or shell word-splitting truncating the payload.","commonSituations":"Passing --data foo=bar instead of JSON; shell stripping inner quotes so JSON.parse fails; hand-built JSON with smart quotes; forgetting to wrap the value in single quotes so spaces split arguments.","solutions":["Quote the whole --data value and use valid JSON: --data '{\"key\":\"value\"}'","Build the payload with a JSON serializer (jq -n, JSON.stringify) instead of hand-writing it","Check the warning output: the raw value is echoed, so inspect what the shell actually passed","If the event legitimately needs no payload, omit --data instead of passing malformed JSON"],"exampleFix":"// before\narchon workflow event emit $RUN done --data status=ok\n# after\narchon workflow event emit $RUN done --data '{\"status\":\"ok\"}'","handlingStrategy":"validation","validationCode":"// Validate --data before invoking the CLI:\nconst raw = process.argv[process.argv.indexOf('--data') + 1];\nif (raw !== undefined) JSON.parse(raw); // throws early with a clear message\n// shell: jq -n --arg s ok '{status: $s}' to build the payload","typeGuard":"function isValidJsonObject(raw) {\n  try { const v = JSON.parse(raw); return typeof v === 'object' && v !== null && !Array.isArray(v); }\n  catch { return false; }\n}","tryCatchPattern":"// The CLI itself warns and continues (fallback: no data payload). To make it fatal:\nconst raw = getValue('--data');\nif (raw !== undefined && !isValidJsonObject(raw)) {\n  throw new Error(`--data must be valid JSON, got: ${raw}`);\n}\nawait workflowEventEmitCommand(runId, eventType, eventData);","preventionTips":["Single-quote the entire --data value in shell so inner quotes survive","Build payloads with jq -n or JSON.stringify instead of hand-writing JSON","Remember the failure is silent-ish: the event still emits with no data, breaking waiters","Omit --data entirely when the event needs no payload"],"tags":["cli","json","event","shell-quoting"],"backgroundTag":"invalid-json-flag-argument","analyzedSha":"0773b9745896ef0612e709c80845a0f7db315b19","analyzedAt":"2026-09-01T02:28:07.064Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}