Skip to content

Improve error handling when setting up and reading a new integration #2387

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Mar 31, 2025
Merged
23 changes: 18 additions & 5 deletions server/adaptors/integrations/repository/integration_reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,24 @@ export class IntegrationReader {

switch (asset.type) {
case 'savedObjectBundle':
resultValue.push({
type: 'savedObjectBundle',
workflows: asset.workflows,
data: JSON.parse(serializedResult.value.data),
});
// Attempt to parse and process the integration data
try {
// Construct and push a savedObjectBundle with workflows and parsed data
resultValue.push({
type: 'savedObjectBundle',
workflows: asset.workflows,
data: JSON.parse(serializedResult.value.data),
});
} catch {
// Return error response if JSON parsing fails
return {
ok: false,
error: new Error(
`While parsing integration data for \`${serializedResult.value.name}\`:\n` +
'The data field is not valid JSON.'
),
};
}
break;
case 'query':
resultValue.push({
Expand Down
10 changes: 9 additions & 1 deletion server/adaptors/integrations/repository/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,15 @@ export async function deepCheck(reader: IntegrationReader): Promise<Result<Integ

// Deep checks not included in default config validation
const assets = await reader.getAssets();
if (!assets.ok || assets.value.length === 0) {
// Check if there was an error retrieving assets
if (!assets.ok) {
return {
ok: false,
error: new Error(`Failed to process assets while loading: ${assets.error.message}`),
};
}
// Validate that at least one asset exists for the integration
if (assets.value.length === 0) {
return { ok: false, error: new Error('An integration must have at least one asset') };
}

Expand Down
Loading