Skip to content

Commit

Permalink
chore: changes in transformation error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
kanishkkatara committed Jun 17, 2024
1 parent bb94c81 commit a80d403
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
11 changes: 7 additions & 4 deletions src/util/ivmFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,15 @@ async function createIvm(code, libraryVersionIds, versionId, credentials, secret
}),
);

await jail.set('_credential', function (key) {
await jail.set('_credential', function (...args) {
if (_.isNil(credentials) || !_.isObject(credentials)) {
throw new Error('Credentials in incorrect format');
logger.error('Error fetching credentials map');
stats.increment('credential_error', { versionId });
return undefined;

Check warning on line 250 in src/util/ivmFactory.js

View check run for this annotation

Codecov / codecov/patch

src/util/ivmFactory.js#L248-L250

Added lines #L248 - L250 were not covered by tests
}
if (key.length > 1 || _.isNil(key[0]) || !_.isString(key[0])) {
throw new Error('Key should be a string');
const key = args[0][0];
if (_.isNil(key)) {
throw new Error('Key should be valid and defined');
}
return credentials[key];
});
Expand Down
6 changes: 6 additions & 0 deletions src/util/prometheus.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,12 @@ class Prometheus {
'module',
],
},
{
name: 'credentials_error',
help: 'Error in fetching credentials count',
type: 'counter',
labelNames: ['versionId'],
},

// Gauges
{
Expand Down
8 changes: 4 additions & 4 deletions test/__tests__/user_transformation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1171,7 +1171,7 @@ describe("User transformation", () => {
expect(fetch).toHaveBeenCalledWith(
`https://api.rudderlabs.com/transformation/getByVersionId?versionId=${versionId}`
);
expect(output[0].error).toMatch(/Key should be a string/);
expect(output[0].error).toMatch(/Key should be valid and defined/);
});

it(`Simple ${name} Test with credentials with multiple arguements for codeVersion 1`, async () => {
Expand All @@ -1185,7 +1185,7 @@ describe("User transformation", () => {
name,
code: `
export function transformEvent(event, metadata) {
event.credentialValue = credential('arg1', 'arg2');
event.credentialValue = credential('key1', 'key2');
return event;
}
`
Expand All @@ -1200,7 +1200,7 @@ describe("User transformation", () => {
expect(fetch).toHaveBeenCalledWith(
`https://api.rudderlabs.com/transformation/getByVersionId?versionId=${versionId}`
);
expect(output[0].error).toMatch(/Key should be a string/);
expect(output[0].transformedEvent.credentialValue).toEqual("value1");
});

it(`Simple ${name} Test with credentials with non string key for codeVersion 1`, async () => {
Expand Down Expand Up @@ -1229,7 +1229,7 @@ describe("User transformation", () => {
expect(fetch).toHaveBeenCalledWith(
`https://api.rudderlabs.com/transformation/getByVersionId?versionId=${versionId}`
);
expect(output[0].error).toMatch(/Key should be a string/);
expect(output[0].transformedEvent.credentialValue).toEqual(undefined);
});

it(`Simple ${name} Test with credentials without value for codeVersion 1`, async () => {
Expand Down

0 comments on commit a80d403

Please sign in to comment.