Skip to content

fix: Tolerate missing directories when formatting from stdin#1848

Merged
belav merged 1 commit into
belav:mainfrom
jennings:missing-directory-ok
Apr 17, 2026
Merged

fix: Tolerate missing directories when formatting from stdin#1848
belav merged 1 commit into
belav:mainfrom
jennings:missing-directory-ok

Conversation

@jennings
Copy link
Copy Markdown
Contributor

@jennings jennings commented Apr 16, 2026

When formatting code passed via stdin, and using --stdin-path, the path passed may not exist. This is the case when using CSharpier as a jj fix tool: Commits are not checked out, so the directory containing the file being formatted may not actually exist on disk.

When this happened, CSharpier was throwing a DirectoryNotFoundException from FindForDirectoryName in CSharpierConfigParser.

Instead, we can predict this exception and check for configuration in the parent directory, until we find one that does exist.

Description

Related Issue

Checklist

  • My code follows the project's code style
    • always var
    • follow existing naming conventions
    • always this.
    • no pointless comments
  • I will not force push after a code review of my PR has started
  • I have added tests that cover my changes

When formatting code passed via stdin, and using `--stdin-path`, the
path passed may not exist. This is the case when using CSharpier as a
[jj] fix tool: Commits are not checked out, so the directory containing
the file being formatted may not actually exist on disk.

When this happened, CSharpier was throwing a DirectoryNotFoundException
from FindForDirectoryName in CSharpierConfigParser.

Instead, we can predict this exception and check for configuration in
the parent directory, until we find one that does exist.

jj: https://jj-vcs.dev
Copy link
Copy Markdown
Owner

@belav belav left a comment

Choose a reason for hiding this comment

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

Looks good, thanks for the contribution!

@belav belav added this to the 1.3.0 milestone Apr 17, 2026
@belav belav merged commit cf023de into belav:main Apr 17, 2026
7 checks passed
@jennings jennings deleted the missing-directory-ok branch April 17, 2026 18:36
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