Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 4, 2025

📝 Changes Description

On Windows with Deno, pyodide.FS.mkdir() throws errors with empty messages when directories exist, causing the e.message.includes('File exists') check to fail silently.

Fix: Use pyodide.FS.analyzePath() to check directory existence before attempting creation, rather than relying on error message content.

// Before: Error message check fails on Windows (empty message)
try {
    pyodide.FS.mkdir(cur);
} catch (e) {
    if (!(e && e.message && e.message.includes('File exists'))) { ... }
}

// After: Platform-agnostic existence check
const pathInfo = pyodide.FS.analyzePath(cur);
if (!pathInfo.exists) {
    pyodide.FS.mkdir(cur);
}

✅ Contributor Checklist

  • Pre-Commit checks are passing (locally and remotely)
  • Title of your PR / MR corresponds to the required format
  • Commit message follows required format {label}(dspy): {message}

⚠️ Warnings

None.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • dl.deno.land
    • Triggering command: /usr/bin/curl curl -s REDACTED /home/REDACTED/work/dspy/dspy/tests/utils/test_exceptions.py /home/REDACTED/work/dspy/dspy/tests/utils/test_langchain_tool.py /home/REDACTED/work/dspy/dspy/tests/utils/test_unbatchify.py /home/REDACTED/work/dspy/dspy/tests/utils/test_asyncify.py /home/REDACTED/work/dspy/dspy/tests/utils/test_mcp.py /home/REDACTED/work/dspy/dspy/tests/utils/test_settings.py /home/REDACTED/work/dspy/dspy/tests/utils/test_usage_tracker.py /home/REDACTED/work/dspy/dspy/tests/utils/__init__.py /home/REDACTED/work/dspy/dspy/tests/streaming/test_streaming.py (dns block)
    • Triggering command: /usr/bin/curl curl -s REDACTED (dns block)
    • Triggering command: /home/REDACTED/.deno/bin/deno deno run --allow-read=/home/REDACTED/work/dspy/dspy/dspy/primitives/REDACTED.js,/home/REDACTED/.cache/deno /home/REDACTED/work/dspy/dspy/dspy/primitives/REDACTED.js (dns block)
  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>[Bug] On windows, code execution using deno does not work because of error description mismatch inside js</issue_title>
<issue_description>### What happened?

Os: windows 11,
dspy Version: 3.0.4
Deno:
deno 2.5.6 (stable, release, x86_64-pc-windows-msvc)
v8 14.0.365.5-rusty
typescript 5.9.2

In the deno script runner.js, when creating a file path with mkdir, existing directory are handled using an error catch like this:
} catch (e) {
if (!(e && e.message && e.message.includes('File exists'))) {
console.log("[DEBUG] Error creating directory in Pyodide file system:", cur, "|", e.message);
}
}
where the script assumes that the error message would contain 'File exists', which is not the case for my version of deno (message is empty for this error).
A more robust approach would be to just test if the directory exists using a function like this:

function directoryExists(path) {
try {
const entry = pyodide.FS.analyzePath(path);
return entry.exists; // True if it's a directory
} catch (e) {
console.log("Error checking directory existence in Pyodide:", e);
return false; // If an error occurs (e.g., path doesn't exist), return false
}
}

I have attached the full updated script that works in my case.

runner.js

Steps to reproduce

When using the code interpreter with file loading:
ex:
dspy.PythonInterpreter({}, enable_read_paths=files_path).execute(expression)

files_path could be any file path and expression can be any expression.
The problem is on
Os: windows 11,
Deno:
deno 2.5.6 (stable, release, x86_64-pc-windows-msvc)
v8 14.0.365.5-rusty
typescript 5.9.2

DSPy version

3.0.4</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: TomeHirata <33407409+TomeHirata@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix error handling for existing directories in Deno Fix Windows Deno directory creation error in runner.js Dec 4, 2025
Copilot AI requested a review from TomeHirata December 4, 2025 07:20
Copilot finished work on behalf of TomeHirata December 4, 2025 07:20
@TomeHirata TomeHirata marked this pull request as ready for review December 4, 2025 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] On windows, code execution using deno does not work because of error description mismatch inside js

2 participants