diff --git a/apps/sim/blocks/blocks/ashby.test.ts b/apps/sim/blocks/blocks/ashby.test.ts index 75a26b13b68..748efee159f 100644 --- a/apps/sim/blocks/blocks/ashby.test.ts +++ b/apps/sim/blocks/blocks/ashby.test.ts @@ -47,11 +47,22 @@ describe('AshbyBlock', () => { expect(result.socialLinks).toEqual([{ type: 'Twitter', url: 'https://twitter.com/jane' }]) }) - it('omits the field when the JSON is malformed', () => { - const result = AshbyBlock.tools.config.params!( - buildParams('update_candidate', { socialLinks: 'not json' }) - ) - expect(result.socialLinks).toBeUndefined() + it('throws instead of silently dropping the field when the JSON is malformed', () => { + // A silent [] here would let the Ashby update proceed without applying + // the requested links and with no error shown to the workflow author. + expect(() => + AshbyBlock.tools.config.params!( + buildParams('update_candidate', { socialLinks: 'not json' }) + ) + ).toThrow(/Invalid JSON in Ashby social links/) + }) + + it('throws when the parsed JSON is not an array', () => { + expect(() => + AshbyBlock.tools.config.params!( + buildParams('update_candidate', { socialLinks: '{"type":"Twitter"}' }) + ) + ).toThrow(/expected a JSON array/) }) }) diff --git a/apps/sim/blocks/blocks/ashby.ts b/apps/sim/blocks/blocks/ashby.ts index 78c63efee30..06fcf157524 100644 --- a/apps/sim/blocks/blocks/ashby.ts +++ b/apps/sim/blocks/blocks/ashby.ts @@ -1,3 +1,4 @@ +import { getErrorMessage } from '@sim/utils/errors' import { AshbyIcon } from '@/components/icons' import { AuthMode, type BlockConfig, type BlockMeta, IntegrationType } from '@/blocks/types' import { getTrigger } from '@/triggers' @@ -22,12 +23,20 @@ function parseStringListInput(value: unknown): string[] { function parseSocialLinksInput(value: unknown): Array<{ type: string; url: string }> { if (Array.isArray(value)) return value as Array<{ type: string; url: string }> if (typeof value !== 'string' || !value.trim()) return [] + let parsed: unknown try { - const parsed = JSON.parse(value) - return Array.isArray(parsed) ? parsed : [] - } catch { - return [] + parsed = JSON.parse(value) + } catch (error) { + throw new Error( + `Invalid JSON in Ashby social links: ${getErrorMessage(error)}. Expected a JSON array like [{"type":"Twitter","url":"https://twitter.com/x"}].` + ) } + if (!Array.isArray(parsed)) { + throw new Error( + 'Invalid Ashby social links: expected a JSON array like [{"type":"Twitter","url":"https://twitter.com/x"}].' + ) + } + return parsed } export const AshbyBlock: BlockConfig = {