mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-06 16:29:04 +00:00
Host: a job list JSON cannot hold is logged and skipped, not thrown out of every state change (#5802 review)
native-job-store's save() serialised outside its guard: a value JSON cannot hold
(a BigInt, a cycle) would still have thrown out of emit() on every change. It is
now reported once per attempt as a programming error, the last good file stays,
and the next good list is saved. A log line only, no app text.
Test: native-job-store.test.mjs "a job list JSON cannot hold ...": fails on
e19adee7e, 8/8 pass here.
This commit is contained in:
1 parent
e19adee7e6
commit
e06e5d8717
2 files changed
+21
-1
No files matched your search
@@ -47,7 +47,13 @@ export function createJobStore(path, {
|
||||
return {
|
||||
save(jobs) {
|
||||
if (closed) return;
|
||||
const text = JSON.stringify(jobs);
|
||||
let text;
|
||||
try { text = JSON.stringify(jobs); }
|
||||
catch (error) {
|
||||
// A value JSON cannot hold (a BigInt, a cycle) is a programming error, not a disk problem: say so and keep the last good file.
|
||||
report(`[strata host] Job history could not be turned into JSON (${error.message}); the last saved history is kept, inference continues.`);
|
||||
return;
|
||||
}
|
||||
if (text === saved) {
|
||||
pending = null;
|
||||
if (timer !== null) clearTimer(timer);
|
||||
|
||||
@@ -104,3 +104,17 @@ test('an unexpected polling callback failure does not leave polling stuck or rej
|
||||
assert.equal(changes,2);
|
||||
await controller.close();
|
||||
});
|
||||
|
||||
// A value JSON cannot hold is reported and skipped like a disk failure: save() never throws out of emit() (GUI-1116 review of #5802).
|
||||
test('a job list JSON cannot hold is reported, the last good file stays, and save does not throw', () => {
|
||||
const f=fixture();
|
||||
f.store.save([{id:'one',state:'done'}]);
|
||||
const cyclic={id:'two'};cyclic.self=cyclic;
|
||||
assert.doesNotThrow(()=>f.store.save([cyclic]));
|
||||
assert.doesNotThrow(()=>f.store.save([{id:'three',size:1n}]));
|
||||
assert.deepEqual(JSON.parse(fs.readFileSync(f.path)),[{id:'one',state:'done'}]);
|
||||
assert.equal(f.warnings.filter(w=>/could not be turned into JSON/.test(w)).length,2);
|
||||
f.store.save([{id:'four',state:'done'}]);
|
||||
assert.deepEqual(JSON.parse(fs.readFileSync(f.path)),[{id:'four',state:'done'}],'the next good list is saved');
|
||||
f.store.close();
|
||||
});
|
||||
Reference in new issue
Block a user