@ai-ecoverse/slicc-kernel 1.60.0 → 1.60.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.
package/dist/node.js CHANGED
@@ -2520,10 +2520,31 @@ var ERRNO_BY_DOM_ERROR = {
2520
2520
  TypeError: "EINVAL",
2521
2521
  NotAllowedError: "EACCES"
2522
2522
  };
2523
- function translate(err, path) {
2523
+ var reported = /* @__PURE__ */ new Set();
2524
+ function translate(err, path, op = "lookup", mapped = true) {
2524
2525
  if (typeof err?.code === "string") return err;
2525
- const name2 = err?.name;
2526
- return fsError(typeof name2 === "string" && ERRNO_BY_DOM_ERROR[name2] || "EIO", path);
2526
+ const raw = err?.name;
2527
+ const name2 = typeof raw === "string" ? raw : "Error";
2528
+ const code = mapped && ERRNO_BY_DOM_ERROR[name2] || "EIO";
2529
+ const error = Object.assign(fsError(code, path), { domName: name2, op, cause: err });
2530
+ if (code !== "EIO") return error;
2531
+ const detail = err?.message;
2532
+ error.message += ` (OPFS ${op}: ${name2}${typeof detail === "string" && detail ? `: ${detail}` : ""})`;
2533
+ if (!reported.has(`${name2}/${op}`)) {
2534
+ reported.add(`${name2}/${op}`);
2535
+ console.warn(
2536
+ `slicc-kernel: ${error.message}, reported as EIO; logged once per error and operation`
2537
+ );
2538
+ }
2539
+ return error;
2540
+ }
2541
+ var META_OPS = ["get", "update", "move", "remove", "links", "under", "all"];
2542
+ function sidecar(meta) {
2543
+ const pathOf = ([first]) => [first, "/"].flat().find((p) => typeof p === "string");
2544
+ const guarded = (op) => (...args) => meta[op].apply(meta, args).catch((err) => {
2545
+ throw translate(err, pathOf(args), "sidecar", false);
2546
+ });
2547
+ return Object.fromEntries(META_OPS.map((op) => [op, guarded(op)]));
2527
2548
  }
2528
2549
  function missing(err) {
2529
2550
  const code = err?.code;
@@ -2608,7 +2629,7 @@ var OpfsFs = class {
2608
2629
  owners = false;
2609
2630
  constructor(root, meta = new MemoryMeta(), channel, options = {}) {
2610
2631
  this.root = root;
2611
- this.meta = meta;
2632
+ this.meta = sidecar(meta);
2612
2633
  this.ranged = options.ranged === true;
2613
2634
  this.channel = channel === void 0 ? void 0 : new BroadcastChannel(channel);
2614
2635
  if (this.channel) {
@@ -2913,7 +2934,8 @@ var OpfsFs = class {
2913
2934
  } catch (err) {
2914
2935
  const name2 = err?.name;
2915
2936
  const again = name2 === "NotReadableError" || locks && LOCKED.has(name2);
2916
- if (!again || attempt >= READ_ATTEMPTS) throw translate(err, path);
2937
+ if (!again || attempt >= READ_ATTEMPTS)
2938
+ throw translate(err, path, locks ? "write" : "read");
2917
2939
  await new Promise((resolve) => setTimeout(resolve, attempt * 10));
2918
2940
  }
2919
2941
  }
@@ -2955,9 +2977,15 @@ var OpfsFs = class {
2955
2977
  true
2956
2978
  );
2957
2979
  return {
2958
- write: (at, bytes) => writable.write({ type: "write", position: at, data: bytes }),
2959
- truncate: (size) => writable.truncate(size),
2960
- close: () => writable.close()
2980
+ write: (at, bytes) => writable.write({ type: "write", position: at, data: bytes }).catch((err) => {
2981
+ throw translate(err, path, "write", false);
2982
+ }),
2983
+ truncate: (size) => writable.truncate(size).catch((err) => {
2984
+ throw translate(err, path, "write", false);
2985
+ }),
2986
+ close: () => writable.close().catch((err) => {
2987
+ throw translate(err, path, "commit", false);
2988
+ })
2961
2989
  };
2962
2990
  }
2963
2991
  async readFile(path) {
@@ -2992,9 +3020,13 @@ var OpfsFs = class {
2992
3020
  const [file, existed, target] = await this.fileFor(path);
2993
3021
  if (!existed) await this.stampNew(target, owner, false);
2994
3022
  if (!existed && content.length === 0) return;
2995
- const writable = await file.createWritable();
2996
- await writable.write(content);
2997
- await writable.close();
3023
+ try {
3024
+ const writable = await file.createWritable();
3025
+ await writable.write(content);
3026
+ await writable.close();
3027
+ } catch (err) {
3028
+ throw translate(err, path, "commit", false);
3029
+ }
2998
3030
  }
2999
3031
  async listing(path) {
3000
3032
  const found = await this.locate(path, true);
@@ -3270,6 +3302,49 @@ var OpfsFs = class {
3270
3302
  return removed;
3271
3303
  }
3272
3304
  };
3305
+ var READS = [
3306
+ "stat",
3307
+ "lstat",
3308
+ "exists",
3309
+ "readFile",
3310
+ "readFileBuffer",
3311
+ "pread",
3312
+ "readdir",
3313
+ "readdirStat",
3314
+ "readlink",
3315
+ "realpath"
3316
+ ];
3317
+ var WRITES = [
3318
+ "writeFile",
3319
+ "pwrite",
3320
+ "truncate",
3321
+ "writeSession",
3322
+ "mkdir",
3323
+ "rm",
3324
+ "link",
3325
+ "rename",
3326
+ "symlink",
3327
+ "chmod",
3328
+ "utimes",
3329
+ "lutimes",
3330
+ "chown"
3331
+ ];
3332
+ for (const [names, op] of [
3333
+ [READS, "read"],
3334
+ [WRITES, "write"]
3335
+ ]) {
3336
+ for (const name2 of names) {
3337
+ const proto = OpfsFs.prototype;
3338
+ const inner = proto[name2];
3339
+ proto[name2] = async function(...args) {
3340
+ try {
3341
+ return await inner.apply(this, args);
3342
+ } catch (err) {
3343
+ throw translate(err, String(args[0]), op, false);
3344
+ }
3345
+ };
3346
+ }
3347
+ }
3273
3348
 
3274
3349
  // src/fs/unlinked.ts
3275
3350
  var UNLINKED_DIR = ".slicc-unlinked";
@@ -11091,9 +11166,9 @@ var Dying = class {
11091
11166
  clear() {
11092
11167
  clearTimeout(this.timer);
11093
11168
  }
11094
- status(reported) {
11169
+ status(reported2) {
11095
11170
  if (this.ending) return [this.ending.code, this.ending.sig];
11096
- return [typeof reported === "number" ? reported : CRASHED, void 0];
11171
+ return [typeof reported2 === "number" ? reported2 : CRASHED, void 0];
11097
11172
  }
11098
11173
  };
11099
11174
  function killThread(thread, caught, sig) {