Skip to content

[Track/Effect/FileSystem] WriteFile decodes JSON byte arrays via O(N) enum-match loop; empty-path guard duplicated across 4 handlers #65

@NikolaRHristov

Description

@NikolaRHristov

Problem

1. WriteFile binary decode

FileSystem.WriteFile accepts file content as either a Value::Array of u64 integers or a base64 Value::String. The array path iterates every element with v.as_u64().map(|n| n as u8) — an enum-variant match per byte. For a 50 KB file this is 50,000 matches. For a 200 KB binary (e.g., .wasm written to workspace storage by an extension) this is 200,000 matches. The filter_map also silently drops elements that fail as_u64(), including negative values that TypeScript serializers can produce for bytes >127 via signed Int8Array, causing silent data corruption.

File: Source/Track/Effect/CreateEffectForRequest/FileSystem.rs

2. Empty-path guard duplication

The empty-path if path_str.is_empty() { return Err(...) } guard is copy-pasted identically across ReadFile, WriteFile, ReadDirectory, and Stat with four slightly different error strings. In Stat the guard fires after run_time.Environment.Require() whereas in ReadFile it fires before — inconsistent ordering.

Fix

  1. Remove the Value::Array decode path from WriteFile. Require base64 Value::String as the sole accepted encoding. Return a clear error if an array is passed: "FileSystem.WriteFile: content must be base64-encoded string, not byte array".
  2. Extract the empty-path guard to a private inline helper:
    #[inline]
    fn require_non_empty_path(method: &str, path: &str) -> Result<(), String> {
        if path.is_empty() {
            Err(format!("{}: empty path (resource not found)", method))
        } else {
            Ok(())
        }
    }
  3. Standardize ordering: validate path before run_time.Environment.Require() in all four handlers.

Additional Scope for Same PR

  • Add a comment on the vscode://schemas-associations/ special-case in ReadFile referencing the VS Code schema service, so future maintainers understand the origin of this hard-coded prefix.
  • Log a follow-up issue: cache FileSystemReader/FileSystemWriter as typed fields on ApplicationRunTime to eliminate the per-call Environment.Require() hash lookup.

Metadata

Metadata

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions