Skip to content

Ensure output directory exists before writing files in http-client-csharp emitter#10138

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-http-client-csharp-error
Draft

Ensure output directory exists before writing files in http-client-csharp emitter#10138
Copilot wants to merge 2 commits intomainfrom
copilot/fix-http-client-csharp-error

Conversation

Copy link
Contributor

Copilot AI commented Mar 25, 2026

writeCodeModel and writeConfiguration call host.writeFile() without ensuring the output directory exists, causing ENOENT when the emitter runs against a clean output path. This affects downstream emitters (e.g. @azure-typespec/http-client-csharp) that call these exported functions before the directory is created by $onEmit.

  • Add await context.program.host.mkdirp(outputFolder) to both writeCodeModel and writeConfiguration, matching the defensive pattern used by the compiler's emitFile utility
  • Update test mock host to include mkdirp, add test asserting directory creation

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:

  • telemetry.astro.build
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /home/REDACTED/work/typespec/typespec/website/node_modules/.bin/../astro/bin/astro.mjs build sh eams�� pnpm gen-version--llmstxt sh /usr/bin/uname --no-emit cat reams/reference uname -p build.json sh k/typespec/typespec/node_modules--output-dir r --no-emit sh s/.bin/tspd sh (dns block)

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


📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

…nt-csharp emitter

Add mkdirp calls to writeCodeModel and writeConfiguration to create the
output directory before writing files, preventing ENOENT errors when the
output directory does not exist. This follows the same pattern as the
compiler's emitFile utility.

Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/9fd1ce42-8ee7-4871-bcb0-b02cca563152
@microsoft-github-policy-service microsoft-github-policy-service bot added the emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp label Mar 25, 2026
Copilot AI changed the title [WIP] Fix http-client-csharp error when metadata.json is missing Ensure output directory exists before writing files in http-client-csharp emitter Mar 25, 2026
Copilot AI requested a review from JoshLove-msft March 25, 2026 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants