Skip to content

Commit

Permalink
fix: 1702: integrate fast-safe-stringify
Browse files Browse the repository at this point in the history
Integrate fast-safe stringify library to also gracefully handles
circular structures instead of throwing in most cases

Closes: #1702
Signed-off-by: Michael Courtin <[email protected]>
  • Loading branch information
m-courtin committed Jan 14, 2022
1 parent f514b32 commit 3bf237d
Show file tree
Hide file tree
Showing 3 changed files with 209 additions and 28 deletions.
6 changes: 6 additions & 0 deletions packages/cactus-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
"name": "Peter Somogyvari",
"email": "[email protected]",
"url": "https://accenture.com"
},
{
"name": "Michael Courtin",
"email": "[email protected]",
"url": "https://accenture.com"
}
],
"license": "Apache-2.0",
Expand All @@ -60,6 +65,7 @@
},
"homepage": "https://github.com/hyperledger/cactus#readme",
"dependencies": {
"fast-safe-stringify": "2.1.1",
"json-stable-stringify": "1.0.1",
"key-encoder": "2.0.3",
"loglevel": "1.7.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { RuntimeError } from "run-time-error";
import stringify from "fast-safe-stringify";

export class LogHelper {
public static getExceptionStack(exception: unknown): string {
Expand Down Expand Up @@ -101,9 +102,10 @@ export class LogHelper {
let message = "";

try {
message = JSON.stringify(input);
// use fast-safe-stringify to also handle gracefully circular structures
message = stringify(input);
} catch (error) {
// stringify failed maybe due to cyclic dependency
// fast and safe stringify failed
message = catchMessage;
}
return message;
Expand Down
Loading

0 comments on commit 3bf237d

Please sign in to comment.