chia-agent 16.0.0 → 16.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/logger.js +34 -13
  3. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## [16.0.1]
4
+ ### Fixed
5
+ - Fixed an issue where it exhausts heap when logging an object with circular references
6
+
3
7
  ## [16.0.0]
4
8
  ### Breaking change
5
9
  - Changed `daemon.connect()` API signature from `connect(url?, timeoutMs?)` to `connect(url?, options?)`
@@ -1882,6 +1886,7 @@ daemon.sendMessage(destination, get_block_record_by_height_command, data);
1882
1886
  Initial release.
1883
1887
 
1884
1888
  <!-- [Unreleased]: https://github.com/Chia-Mine/chia-agent/compare/v0.0.1...v0.0.2 -->
1889
+ [16.0.1]: https://github.com/Chia-Mine/chia-agent/compare/v16.0.0...v16.0.1
1885
1890
  [16.0.0]: https://github.com/Chia-Mine/chia-agent/compare/v15.0.0...v16.0.0
1886
1891
  [15.0.0]: https://github.com/Chia-Mine/chia-agent/compare/v14.5.0...v15.0.0
1887
1892
  [14.5.0]: https://github.com/Chia-Mine/chia-agent/compare/v14.4.0...v14.5.0
package/logger.js CHANGED
@@ -176,19 +176,40 @@ function stringify(obj, indent) {
176
176
  else if (typeof obj === "function") {
177
177
  return "[Function]";
178
178
  }
179
- const seen = new WeakSet();
180
- return JSON.stringify(obj, (_k, v) => {
181
- if (typeof v === "object" && v !== null) {
182
- if (seen.has(v)) {
183
- return undefined;
184
- }
185
- seen.add(v);
186
- }
187
- else if (typeof v === "bigint") {
188
- return `${v}n`;
189
- }
190
- return v;
191
- }, indent);
179
+ else if (obj === null) {
180
+ return "null";
181
+ }
182
+ try {
183
+ // Custom replacer for circular references
184
+ const getCircularReplacer = () => {
185
+ const seen = new WeakSet();
186
+ return (_key, value) => {
187
+ if (typeof value === "object" && value !== null) {
188
+ if (seen.has(value)) {
189
+ return "[Circular]";
190
+ }
191
+ seen.add(value);
192
+ }
193
+ else if (typeof value === "bigint") {
194
+ return `${value}n`;
195
+ }
196
+ else if (typeof value === "function") {
197
+ return "[Function]";
198
+ }
199
+ else if (typeof value === "symbol") {
200
+ return value.toString();
201
+ }
202
+ return value;
203
+ };
204
+ };
205
+ return JSON.stringify(obj, getCircularReplacer(), indent);
206
+ }
207
+ catch (error) {
208
+ const msg = error && typeof error === "object" && "message" in error
209
+ ? error.message
210
+ : "Unknown error";
211
+ return `[Error stringifying object: ${msg}]`;
212
+ }
192
213
  }
193
214
  class Logger {
194
215
  constructor(name, logLevel, writer, formatter) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chia-agent",
3
- "version": "16.0.0",
3
+ "version": "16.0.1",
4
4
  "author": "ChiaMineJP <admin@chiamine.jp>",
5
5
  "description": "chia rpc/websocket client library",
6
6
  "license": "MIT",