openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 1.8 kB
JavaScript
import{canUseRootFileOpen,matchRootFileOpenFailure,matchRootFileOpenFailure as matchRootFileOpenFailure$1,openRootFile,openRootFileSync as openRootFileSync$1,readFileDescriptorBounded,readFileDescriptorBoundedSync}from"@openclaw/fs-safe/advanced";import{FsSafeError}from"@openclaw/fs-safe/errors";
//!src/infra/boundary-file-read.ts
const MISSING_PATH_ERROR_CODES=/* @__PURE__ */ new Set([`ENOENT`,`ENOTDIR`]);function readFailureErrorCode(e){const t=e&&typeof e===`object`?e.code:void 0;return typeof t===`string`&&t?t:void 0}function isRootFileMissingFailure(e){return e.reason===`path`&&MISSING_PATH_ERROR_CODES.has(readFailureErrorCode(e.error)??``)}function describeRootFileOpenFailure(e){const unreadable=t=>`${e.subject} could not be read${t?` (${t})`:``}: ${e.filePath}`;return matchRootFileOpenFailure(e.failure,{path:t=>{const n=readFailureErrorCode(t.error);return isRootFileMissingFailure(t)?`${e.subject} not found: ${e.filePath}`:unreadable(n)},validation:()=>`${e.subject} escapes ${e.boundaryLabel} or fails alias checks: ${e.filePath}`,fallback:e=>unreadable(readFailureErrorCode(e.error))})}function preserveOpenClawOverflowError(e,t){if(e instanceof FsSafeError&&e.code===`too-large`)throw new RangeError(`File exceeds ${t} bytes`,{cause:e});throw e}async function readFileDescriptorBounded$1(e,t){try{return await readFileDescriptorBounded(e,t)}catch(e){return preserveOpenClawOverflowError(e,t)}}function readFileDescriptorBoundedSync$1(e,t){try{return readFileDescriptorBoundedSync(e,t)}catch(e){return preserveOpenClawOverflowError(e,t)}}export{openRootFile as a,readFileDescriptorBoundedSync$1 as c,matchRootFileOpenFailure$1 as i,describeRootFileOpenFailure as n,openRootFileSync$1 as o,isRootFileMissingFailure as r,readFileDescriptorBounded$1 as s,canUseRootFileOpen as t};