Skip to content

Commit 29cf3e7

Browse files
authored
fix(ashby): fail loudly instead of silently dropping malformed socialLinks (#5624)
* 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). * fix(ashby): use getErrorMessage instead of inline error-message extraction check:utils bans the e instanceof Error ? e.message : fallback pattern in favor of getErrorMessage(e, fallback?) from @sim/utils/errors.
1 parent b20bbdc commit 29cf3e7

2 files changed

Lines changed: 29 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: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getErrorMessage } from '@sim/utils/errors'
12
import { AshbyIcon } from '@/components/icons'
23
import { AuthMode, type BlockConfig, type BlockMeta, IntegrationType } from '@/blocks/types'
34
import { getTrigger } from '@/triggers'
@@ -22,12 +23,20 @@ function parseStringListInput(value: unknown): string[] {
2223
function parseSocialLinksInput(value: unknown): Array<{ type: string; url: string }> {
2324
if (Array.isArray(value)) return value as Array<{ type: string; url: string }>
2425
if (typeof value !== 'string' || !value.trim()) return []
26+
let parsed: unknown
2527
try {
26-
const parsed = JSON.parse(value)
27-
return Array.isArray(parsed) ? parsed : []
28-
} catch {
29-
return []
28+
parsed = JSON.parse(value)
29+
} catch (error) {
30+
throw new Error(
31+
`Invalid JSON in Ashby social links: ${getErrorMessage(error)}. Expected a JSON array like [{"type":"Twitter","url":"https://twitter.com/x"}].`
32+
)
3033
}
34+
if (!Array.isArray(parsed)) {
35+
throw new Error(
36+
'Invalid Ashby social links: expected a JSON array like [{"type":"Twitter","url":"https://twitter.com/x"}].'
37+
)
38+
}
39+
return parsed
3140
}
3241

3342
export const AshbyBlock: BlockConfig = {

0 commit comments

Comments
 (0)