Skip to content

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Sep 25, 2025

The export_index.py tool was crashing when provided with simple filenames instead of full directory paths. For example:

# This would crash with FileNotFoundError
python tools/export_index.py --json templates.json --csv templates.csv

# But this would work fine  
python tools/export_index.py --json output/templates.json --csv output/templates.csv

Root Cause
When a filename without directory separators is provided (like templates.json), os.path.dirname() returns an empty string. The code was then calling os.makedirs('') which fails with:

FileNotFoundError: [Errno 2] No such file or directory: ''

Solution
Modified both write_csv() and write_json() functions to only call os.makedirs() when the directory path is non-empty. This preserves the existing behavior for paths with directories while fixing the crash for simple filenames.

Changes

  • Added directory path validation in write_csv() before calling os.makedirs()
  • Added directory path validation in write_json() before calling os.makedirs()

Testing

  • ✅ Simple filenames now work: templates.json, data.csv
  • ✅ Directory paths still work: output/templates.json, data/export.csv
  • ✅ Nested directories are created as before: nested/deep/path/file.json
  • ✅ All existing functionality preserved
  • ✅ Output format and content unchanged

This is a minimal, backward-compatible fix that makes the tool more user-friendly by supporting the most common use case of exporting to the current directory.

Original prompt

fix


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] fix Fix export_index.py crash when using filenames without directories Sep 25, 2025
@Copilot Copilot AI requested a review from sahiixx September 25, 2025 09:05
Copilot finished work on behalf of sahiixx September 25, 2025 09:05
@sahiixx sahiixx marked this pull request as ready for review September 25, 2025 09:13
@Copilot Copilot AI review requested due to automatic review settings September 25, 2025 09:13
@sahiixx sahiixx merged commit b6ef6f3 into main Sep 25, 2025
0 of 2 checks passed
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Fixes a crash in the export_index.py tool when using simple filenames without directory paths by adding validation before creating directories.

  • Added directory path validation in write_csv() and write_json() functions
  • Prevents os.makedirs('') calls that cause FileNotFoundError when using simple filenames
  • Maintains backward compatibility for existing directory-based paths

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

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.

2 participants