Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions apps/sim/blocks/blocks/ashby.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
})
})

Expand Down
17 changes: 13 additions & 4 deletions apps/sim/blocks/blocks/ashby.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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 = {
Expand Down
Loading