Conversation
…mproved structure
There was a problem hiding this comment.
2 issues found across 121 files
Note: This PR contains a large number of files. cubic only reviews up to 75 files per PR, so some files may not have been reviewed.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="src/commands/emails/batch.ts">
<violation number="1" location="src/commands/emails/batch.ts:74">
P1: The `parseJson` call uses error code 'invalid_json' for both JSON parse failures AND validation failures. This breaks the command's error contract - the help text still advertises 'invalid_format' for valid JSON with wrong shape, but the new code will never return it. Both malformed JSON `{}` and valid JSON `{}` (not an array) now return 'invalid_json'. Consider using 'invalid_format' for the guard failure case to preserve the previous behavior.</violation>
</file>
<file name="src/commands/contacts/utils.ts">
<violation number="1" location="src/commands/contacts/utils.ts:83">
P2: The `parseTopicsJson` type guard only validates that the payload is an array, not that elements match the required `{id: string; subscription: 'opt_in' | 'opt_out'}` shape. Invalid inputs like `[1]`, `[{"id":123}]`, or `[{"subscription":"maybe"}]` will bypass validation and fail downstream.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| (x): x is unknown[] => Array.isArray(x), | ||
| { | ||
| message: 'File content must be a valid JSON array of email objects.', | ||
| code: 'invalid_json', |
There was a problem hiding this comment.
P1: The parseJson call uses error code 'invalid_json' for both JSON parse failures AND validation failures. This breaks the command's error contract - the help text still advertises 'invalid_format' for valid JSON with wrong shape, but the new code will never return it. Both malformed JSON {} and valid JSON {} (not an array) now return 'invalid_json'. Consider using 'invalid_format' for the guard failure case to preserve the previous behavior.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/commands/emails/batch.ts, line 74:
<comment>The `parseJson` call uses error code 'invalid_json' for both JSON parse failures AND validation failures. This breaks the command's error contract - the help text still advertises 'invalid_format' for valid JSON with wrong shape, but the new code will never return it. Both malformed JSON `{}` and valid JSON `{}` (not an array) now return 'invalid_json'. Consider using 'invalid_format' for the guard failure case to preserve the previous behavior.</comment>
<file context>
@@ -66,27 +66,15 @@ export const batchCommand = new Command('batch')
+ (x): x is unknown[] => Array.isArray(x),
+ {
+ message: 'File content must be a valid JSON array of email objects.',
+ code: 'invalid_json',
+ },
+ globalOpts,
</file context>
Summary by cubic
Restructured the CLI to centralize output formatting and input validation into
lib/formattersandlib/validators, standardizing errors and simplifying imports. Also adds stronger, type‑guarded JSON parsing for contacts topics and unifies key=value parsing across commands.Refactors
lib/output,lib/help-text, andlib/tablewithlib/formatters(buildHelpText,renderTable,errorMessage,outputError,outputResult) and updated all commands.lib/validators(validateProfileName,parseLimitOpt,parseJson,parseKeyValuePairs,parseVariables) and updated usages across emails, contacts, templates, and receiving.Bug Fixes
invalid_jsonfor malformed JSON (including email batch arrays),invalid_varfor template--var,invalid_header/invalid_tagvia shared key=value parser, andinvalid_topicswith schema validation for--topics.Written for commit b5efa18. Summary will update on new commits.