aboutsummaryrefslogtreecommitdiff
path: root/modules/core/virtual-fs.js
diff options
context:
space:
mode:
authorAgando <roduccomm@gmail.com>2026-10-23 18:25:52 +0200
committerAgando <roduccomm@gmail.com>2026-10-23 18:25:52 +0200
commit9c27d3790b594c94430015675c91ce618c61be1d (patch)
treed7f8be0f194d3bb8346a77d9e4b63b53d41200d7 /modules/core/virtual-fs.js
parent2bc11203b73fe2eb210ce3dd643773e625609c25 (diff)
fix(newos4): an invalid grep pattern returns a message, not an exception (v4.6.64)
Packet 8. `new RegExp(pattern)` sat unguarded in the terminal grep handler and in VFS find()/grep(), so a bad pattern threw out of the command handler into the error ledger -- the same ledger packet 2 had to stop trusting. - module-fs.js grep: compile in try/catch, print "grep: invalid pattern: <pattern> (<engine message>)" as a warning and return - virtual-fs.js find()/grep(): same guard, return [] and stash the message on _lastPatternError instead of throwing into the module error wrapper Verified live on v4.6.64 with the packet's own repro: `grep "/\bug_id\" file` prints the message, the error counter stays 0 (was: one ledger entry per call), a valid pattern still matches, and fs.grep('[') returns [] instead of throwing.
Diffstat (limited to 'modules/core/virtual-fs.js')
-rw-r--r--modules/core/virtual-fs.js10
1 files changed, 8 insertions, 2 deletions
diff --git a/modules/core/virtual-fs.js b/modules/core/virtual-fs.js
index c9eb7a3..a52a393 100644
--- a/modules/core/virtual-fs.js
+++ b/modules/core/virtual-fs.js
@@ -822,7 +822,10 @@ class VirtualFileSystem {
dir = resolved.dir;
}
const results = [];
- const regex = new RegExp(pattern, 'i');
+ // v4.6.64: an invalid pattern must not throw into the error ledger (packet §8).
+ let regex;
+ try { regex = new RegExp(pattern, 'i'); }
+ catch (e) { this._lastPatternError = e.message; return []; }
for (const name of Object.keys(dir.content)) {
const fullPath = path ? path + '/' + name : name;
if (regex.test(name)) {
@@ -836,7 +839,10 @@ class VirtualFileSystem {
}
grep(pattern, path = '') {
const results = [];
- const regex = new RegExp(pattern, 'i');
+ // v4.6.64: see find() above — a bad pattern is a result, not an exception.
+ let regex;
+ try { regex = new RegExp(pattern, 'i'); }
+ catch (e) { this._lastPatternError = e.message; return []; }
const files = this.find('.', path).filter(e => e.type === 'file');
for (const file of files) {
const content = this.readFile(file.path);