Skip to content

Commit a1ff635

Browse files
committed
fix(ashby): fail loudly instead of silently dropping malformed socialLinks
parseSocialLinksInput returned [] for any non-JSON-parseable input, and tools.config.params only sets result.socialLinks when the parsed array is non-empty — so a malformed socialLinks string (user typo, or a wand response that didn't follow the JSON-array prompt) silently omitted the field entirely. The Ashby candidate.update call then succeeded without applying the requested links, with no error surfaced to the workflow author. Throw a clear error instead, matching the existing throw-on-invalid-JSON pattern used elsewhere (e.g. blocks/airtable.ts).
1 parent 5dec4f3 commit a1ff635

2 files changed

Lines changed: 28 additions & 9 deletions

File tree

apps/sim/blocks/blocks/ashby.test.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,22 @@ describe('AshbyBlock', () => {
4747
expect(result.socialLinks).toEqual([{ type: 'Twitter', url: 'https://twitter.com/jane' }])
4848
})
4949

50-
it('omits the field when the JSON is malformed', () => {
51-
const result = AshbyBlock.tools.config.params!(
52-
buildParams('update_candidate', { socialLinks: 'not json' })
53-
)
54-
expect(result.socialLinks).toBeUndefined()
50+
it('throws instead of silently dropping the field when the JSON is malformed', () => {
51+
// A silent [] here would let the Ashby update proceed without applying
52+
// the requested links and with no error shown to the workflow author.
53+
expect(() =>
54+
AshbyBlock.tools.config.params!(
55+
buildParams('update_candidate', { socialLinks: 'not json' })
56+
)
57+
).toThrow(/Invalid JSON in Ashby social links/)
58+
})
59+
60+
it('throws when the parsed JSON is not an array', () => {
61+
expect(() =>
62+
AshbyBlock.tools.config.params!(
63+
buildParams('update_candidate', { socialLinks: '{"type":"Twitter"}' })
64+
)
65+
).toThrow(/expected a JSON array/)
5566
})
5667
})
5768

apps/sim/blocks/blocks/ashby.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,20 @@ function parseStringListInput(value: unknown): string[] {
2222
function parseSocialLinksInput(value: unknown): Array<{ type: string; url: string }> {
2323
if (Array.isArray(value)) return value as Array<{ type: string; url: string }>
2424
if (typeof value !== 'string' || !value.trim()) return []
25+
let parsed: unknown
2526
try {
26-
const parsed = JSON.parse(value)
27-
return Array.isArray(parsed) ? parsed : []
28-
} catch {
29-
return []
27+
parsed = JSON.parse(value)
28+
} catch (error) {
29+
throw new Error(
30+
`Invalid JSON in Ashby social links: ${error instanceof Error ? error.message : String(error)}. Expected a JSON array like [{"type":"Twitter","url":"https://twitter.com/x"}].`
31+
)
3032
}
33+
if (!Array.isArray(parsed)) {
34+
throw new Error(
35+
'Invalid Ashby social links: expected a JSON array like [{"type":"Twitter","url":"https://twitter.com/x"}].'
36+
)
37+
}
38+
return parsed
3139
}
3240

3341
export const AshbyBlock: BlockConfig = {

0 commit comments

Comments
 (0)