Skip to content

fix: coerce numeric fallback values in contact-properties update command#226

Merged
felipefreitag merged 5 commits intomainfrom
fix/contact-property-numeric-fallback-6ced
Apr 9, 2026
Merged

fix: coerce numeric fallback values in contact-properties update command#226
felipefreitag merged 5 commits intomainfrom
fix/contact-property-numeric-fallback-6ced

Conversation

@bukinoshita
Copy link
Copy Markdown
Member

@bukinoshita bukinoshita commented Apr 9, 2026

The update command never looks up the property's declared type and never coerces --fallback-value. Commander supplies option values as strings, so --fallback-value 42 becomes '42' and is forwarded unchanged.

const fallbackValue = opts.clearFallbackValue ? null : opts.fallbackValue;

await runWrite(
  {
    sdkCall: (resend) =>
      resend.contactProperties.update({
        id,
        ...(fallbackValue !== undefined && { fallbackValue }),
      }),
  },
  globalOpts,
);

By contrast, the create command explicitly converts numeric fallbacks to numbers and rejects non-numeric input for type === 'number':

let fallbackValue: string | number | undefined;
if (opts.fallbackValue !== undefined) {
  if (type === 'number') {
    const parsed = parseFloat(opts.fallbackValue);
    if (Number.isNaN(parsed)) {
      outputError({
        message: '--fallback-value must be a valid number for number-type properties.',
        code: 'invalid_fallback_value',
      });
    }
    fallbackValue = parsed;
  } else {
    fallbackValue = opts.fallbackValue;
  }
}

The test suite also encodes this inconsistency:

  • create test expects numeric coercion to 42
  • update test only validates string passthrough and has no numeric case
await createContactPropertyCommand.parseAsync(
  ['--key', 'score', '--type', 'number', '--fallback-value', '42'],
  { from: 'user' },
);
expect(args.fallbackValue).toBe(42);
await updateContactPropertyCommand.parseAsync(
  ['b4a3c2d1-6e5f-8a7b-0c9d-2e1f4a3b6c5d', '--fallback-value', 'Acme Corp'],
  { from: 'user' },
);
expect(args.fallbackValue).toBe('Acme Corp');

The update command forwarded --fallback-value as a raw string from Commander,
so numeric inputs like '42' were sent to the Resend API as strings instead of
numbers. This violated the API contract requiring fallback_value to match the
property's declared type.

Now the update command fetches the existing property to determine its type and
coerces/validates --fallback-value accordingly, mirroring the create command's
behavior.

Added regression tests for numeric coercion, string passthrough, and invalid
numeric fallback validation on update.

Co-authored-by: Bu Kinoshita <bukinoshita@users.noreply.github.com>
@bukinoshita bukinoshita marked this pull request as ready for review April 9, 2026 18:55
Copy link
Copy Markdown
Contributor

@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.

1 issue found across 2 files

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/contact-properties/update.ts">

<violation number="1" location="src/commands/contact-properties/update.ts:93">
P2: Help metadata error code list is outdated and omits newly introduced runtime errors (`fetch_error`, `invalid_fallback_value`).</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.

@felipefreitag felipefreitag self-requested a review April 9, 2026 19:24
Copy link
Copy Markdown
Contributor

@felipefreitag felipefreitag left a comment

Choose a reason for hiding this comment

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

Just the issue Cubic pointed out

Add `fetch_error` and `invalid_fallback_value` to the errorCodes list
in the help text, matching the error codes actually used in the command.
@felipefreitag felipefreitag merged commit e9263d8 into main Apr 9, 2026
7 checks passed
@felipefreitag felipefreitag deleted the fix/contact-property-numeric-fallback-6ced branch April 9, 2026 20:57
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.

3 participants