Last 12 weeks · 6 commits
4 of 6 standards met
An issue I found when throwing deserialized errors is that the thrown error has no reference to this point. I think the "correct" way to throw serialized errors would be something like: Two drawbacks: doesn't benefit from https://github.com/sindresorhus/serialize-error/pull/70 this isn't necessarily what people want or expect by default So how about:
I've been profiling my application and noticed that has become a bit of a bottleneck in hot paths where errors are serialized frequently. I identified several inefficiencies in the function. Current Issues 1. O(n²) memory from copying array on each recursion For deeply nested objects, this creates significant memory pressure and GC overhead. 2. Linear search for circular reference detection is O(n), which compounds poorly with deep/wide object graphs. 3. Unnecessary intermediate array allocation allocates a new array of tuples on every call. Proposed Fixes Use a Set with backtracking instead of copied arrays This changes: O(n²) memory → O(n) O(n) circular checks → O(1) Replace Object.entries with for...in
Repository: sindresorhus/serialize-error. Description: Serialize/deserialize an error into a plain object Stars: 598, Forks: 69. Primary language: JavaScript. Languages: JavaScript (96%), TypeScript (4%). License: MIT. Latest release: v13.0.1 (1mo ago). Open PRs: 0, open issues: 3. Last activity: 1mo ago. Community health: 85%. Top contributors: sindresorhus, fregante, BendingBender, Weakky, rj-david, misozask, jackple, hec10r, braco, vladimiry and others.
While I am unsure that this is the best place to mention this, I ran into the following issue: I saw that there is a way to define a factory function to register complex error constructors. However, I then had to realize that this feature is not yet available in the npm release of this package. The last released version is over a year old at this point. Would it be possible to release a new version to NPM? I know I could just use the package from GitHub directly, but I do not like doing that in production apps.