-
Notifications
You must be signed in to change notification settings - Fork 372
Open
Description
Summary
SonaEngine.getStats() in ruvector 0.2.12 crashes with a SyntaxError because the native Rust binding returns a Rust struct debug string (e.g., CoordinatorStats { trajectories_buffered: 0, ... }) but the JavaScript wrapper at dist/core/sona-wrapper.js:231 calls JSON.parse() on it.
Environment
- ruvector: 0.2.12
- Node.js: 22.17.1
- Platform: Windows (MINGW64), win32-x64
- Install method: npm
Steps to Reproduce
const { SonaEngine } = require('ruvector');
const sona = new SonaEngine(384);
console.log(sona.getStats()); // CRASHESExpected Behavior
getStats() should return a JavaScript object like:
{ trajectories_buffered: 0, trajectories_dropped: 0, buffer_success_rate: 1.0, patterns_stored: 0, ewc_tasks: 0, instant_enabled: true, background_enabled: true }Actual Behavior
The native binding returns a Rust debug-format string:
CoordinatorStats { trajectories_buffered: 0, trajectories_dropped: 0, buffer_success_rate: 1.0, patterns_stored: 0, ewc_tasks: 0, instant_enabled: true, background_enabled: true }
Then sona-wrapper.js line 231 does JSON.parse() on this string, which throws:
SyntaxError: Unexpected token 'C', "Coordinato"... is not valid JSON
Root Cause
The Rust NAPI binding for getStats() appears to use format!("{:?}", stats) or Display impl instead of serializing to JSON via serde. The wrapper assumes JSON output.
Workaround
// Use string coercion instead of the wrapper's getStats()
const statsStr = '' + sona.getStats(); // Works but returns unparseable stringSuggested Fix
Either:
- Rust side: Return
serde_json::to_string(&stats)from the NAPI binding - JS side: Parse the Rust struct string format, or catch the error and return raw
File Reference
dist/core/sona-wrapper.js, line 231:
getStats() {
return JSON.parse(this._native.getStats()); // <-- crashes here
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels