Skip to content

fix: restructure lib#102

Open
Shubhdeep12 wants to merge 2 commits intoresend:mainfrom
Shubhdeep12:fix/structure
Open

fix: restructure lib#102
Shubhdeep12 wants to merge 2 commits intoresend:mainfrom
Shubhdeep12:fix/structure

Conversation

@Shubhdeep12
Copy link

@Shubhdeep12 Shubhdeep12 commented Mar 14, 2026

  • added formatters/ and validators/
  • and fixed imports
  • moved some validations to global lib/validators

Summary by cubic

Restructured the CLI to centralize output formatting and input validation into lib/formatters and lib/validators, standardizing errors and simplifying imports. Also adds stronger, type‑guarded JSON parsing for contacts topics and unifies key=value parsing across commands.

  • Refactors

    • Replaced lib/output, lib/help-text, and lib/table with lib/formatters (buildHelpText, renderTable, errorMessage, outputError, outputResult) and updated all commands.
    • Moved validation to lib/validators (validateProfileName, parseLimitOpt, parseJson, parseKeyValuePairs, parseVariables) and updated usages across emails, contacts, templates, and receiving.
    • Unified JSON parsing (e.g., email batch file) and removed command-local helpers in favor of shared validators.
  • Bug Fixes

    • Consistent error codes/messages: invalid_json for malformed JSON (including email batch arrays), invalid_var for template --var, invalid_header/invalid_tag via shared key=value parser, and invalid_topics with schema validation for --topics.
    • Prevents silent failures by pre-validating flags and inputs before API requests.

Written for commit b5efa18. Summary will update on new commits.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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',
Copy link

@cubic-dev-ai cubic-dev-ai bot Mar 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Fix with Cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant