Skip to content
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

fix(1557): fix for big int serialization #1581

Merged
merged 3 commits into from
Dec 17, 2024
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
3 changes: 3 additions & 0 deletions packages/errors/src/helpers/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ const stringifyData = (data: unknown): string => {
}
seen.add(value);
}
if (typeof value === 'bigint') {
return value.toString() + 'n';
}
return value;
};
};
Expand Down
55 changes: 4 additions & 51 deletions packages/errors/tests/helpers/helpers.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,65 +73,18 @@ describe('Error package helpers unit tests', () => {
});

/**
* Error message builder function
* An error message is built with big int data
*/
test('Should be able to build an error message', () => {
test('Should be able to build an error message - bigint', () => {
const errorMessage = createErrorMessage(
'simpleMethod',
'Error message',
{
data: 'test'
},
new Error('Internal error')
);
expect(errorMessage).toBeDefined();
});

/**
* An error message is built with inner error undefined
*/
test('Should be able to build an error message - inner error undefined', () => {
const errorMessage = createErrorMessage(
'simpleMethod',
'Error message',
{
data: 'test'
}
);
expect(errorMessage).toBeDefined();
});

/**
* An error message is built with circular dependency on data
*/
test('Should be able to build an error message - circular dependency', () => {
// Simple circular dependency object
const circularDependencyObject: {
prop1: string;
prop2: {
prop3: string;
prop4?: unknown;
};
} = {
prop1: 'value1',
prop2: {
prop3: 'value3'
data: 10n
}
};

// Introduce circular reference
circularDependencyObject.prop2.prop4 = circularDependencyObject;

const errorMessage = createErrorMessage(
'simpleMethod',
'Error message',
{
params: [-1],
data: circularDependencyObject
},
new Error('Internal error')
);
expect(errorMessage).toBeDefined();
expect(errorMessage).toContain('10n');
});
});

Expand Down
Loading