Skip to content

feat: add FileStore exception types#353

Open
wangxiaoxuan273 wants to merge 9 commits into
oras-project:mainfrom
wangxiaoxuan273:feat/filestore-exceptions
Open

feat: add FileStore exception types#353
wangxiaoxuan273 wants to merge 9 commits into
oras-project:mainfrom
wangxiaoxuan273:feat/filestore-exceptions

Conversation

@wangxiaoxuan273

@wangxiaoxuan273 wangxiaoxuan273 commented Feb 27, 2026

Copy link
Copy Markdown
Contributor

What this PR does / why we need it

Adds 5 exception types for FileStore operations:

  • DuplicateFileNameException — thrown when a name already exists in the FileStore
  • FileStoreClosedException — thrown when an operation is attempted on a closed FileStore
  • MissingNameException — thrown when a name is required but not provided
  • OverwriteDisallowedException — thrown when overwriting is not allowed
  • PathTraversalDisallowedException — thrown when a path traversal attempt is detected

Which issue(s) this PR resolves / fixes

Part of the File Store implementation split (issue 3 of 10).
Related: #328, #37

Please check the following list

  • Does the affected code have corresponding tests, e.g. unit test, E2E test?
  • Does this change require a documentation update?
  • Does this introduce breaking changes that would require an announcement or bumping the major version?
  • Do all new files have an appropriate license header?

@codecov

codecov Bot commented Feb 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.90%. Comparing base (5953fb1) to head (1db2f1a).
⚠️ Report is 27 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #353      +/-   ##
==========================================
+ Coverage   91.76%   91.90%   +0.14%     
==========================================
  Files          64       69       +5     
  Lines        2755     2803      +48     
  Branches      364      364              
==========================================
+ Hits         2528     2576      +48     
  Misses        138      138              
  Partials       89       89              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces 5 new exception types specifically for FileStore operations as part of the larger File Store implementation effort (issue 3 of 10, related to PR #328). The exceptions cover various error scenarios: duplicate names, closed store operations, missing names, disallowed overwrites, and path traversal attempts. Each exception includes comprehensive constructor tests (25 test methods total) covering all constructor variations.

Changes:

  • Added 5 new exception types for FileStore operations with appropriate base classes (IOException, ArgumentException, InvalidOperationException)
  • Implemented comprehensive constructor tests validating default messages, custom messages, null handling, and inner exceptions
  • Used a default message pattern with null-coalescing operators in all exception constructors

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/OrasProject.Oras/Content/File/Exceptions/DuplicateNameException.cs New IOException for when a name already exists in FileStore; uses default message pattern
src/OrasProject.Oras/Content/File/Exceptions/FileStoreClosedException.cs New InvalidOperationException for operations on closed FileStore; uses default message pattern
src/OrasProject.Oras/Content/File/Exceptions/MissingNameException.cs New ArgumentException for missing required names; uses default message pattern
src/OrasProject.Oras/Content/File/Exceptions/OverwriteDisallowedException.cs New IOException for disallowed file overwrites; uses default message pattern
src/OrasProject.Oras/Content/File/Exceptions/PathTraversalDisallowedException.cs New IOException for disallowed path traversal attempts; uses default message pattern
tests/OrasProject.Oras.Tests/Content/File/Exceptions/ExceptionTest.cs Comprehensive tests for all 5 exception constructors with message and inner exception validation

Comment thread src/OrasProject.Oras/Content/File/Exceptions/FileStoreClosedException.cs Outdated
Comment thread src/OrasProject.Oras/Content/File/Exceptions/DuplicateNameException.cs Outdated
Comment thread src/OrasProject.Oras/Content/File/Exceptions/PathTraversalDisallowedException.cs Outdated
Comment thread src/OrasProject.Oras/Content/File/Exceptions/OverwriteDisallowedException.cs Outdated
Comment thread src/OrasProject.Oras/Content/File/Exceptions/MissingNameException.cs Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Remove _defaultMessage constant and null-coalescing pattern
from all FileStore exceptions to match existing codebase
convention (e.g., NotFoundException). Simplify tests to use
Assert.ThrowsAsync pattern matching ExceptionTest.cs.

Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Comment thread src/OrasProject.Oras/Content/File/Exceptions/DuplicateNameException.cs Outdated
…llowedException.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Copilot AI review requested due to automatic review settings February 27, 2026 08:21
…ption.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comment thread src/OrasProject.Oras/Content/File/Exceptions/FileStoreClosedException.cs Outdated
…ception.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Copilot AI review requested due to automatic review settings February 27, 2026 08:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Comment thread src/OrasProject.Oras/Content/File/Exceptions/DuplicateFileNameException.cs Outdated
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Comment thread src/OrasProject.Oras/Content/File/Exceptions/DuplicateFileNameException.cs Outdated
Comment thread tests/OrasProject.Oras.Tests/Content/File/Exceptions/ExceptionTest.cs Outdated
…Exception.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Copilot AI review requested due to automatic review settings February 27, 2026 08:49
…Test.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

@akashsinghal akashsinghal left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Caution

This review was generated by Copilot using Claude Opus 4.6, mimicking the review style of shizhMSFT. This is not the real shizhMSFT.

Clean exception type definitions, consistent with the established pattern. A few observations below.

- Change PathTraversalDisallowedException base class from IOException
  to UnauthorizedAccessException (security boundary violation)
- Add paramName constructor to MissingNameException to follow
  the ArgumentException contract
- Replace async Assert.ThrowsAsync with direct instantiation and
  property verification in all exception constructor tests
  (no async operations involved)
- Apply same test pattern fix to Content, Exceptions, Registry,
  and Registry/Remote exception tests for consistency

Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.


You can also share your feedback on Copilot code review. Take the survey.

@akashsinghal

Copy link
Copy Markdown
Collaborator

Caution

This review was generated by Copilot using Claude Opus 4.6, mimicking the review style of shizhMSFT. This is not the real shizhMSFT.

Second-round review of PR #353

All 19 prior threads addressed — PathTraversalDisallowedException base changed to UnauthorizedAccessException, MissingNameException now has paramName constructor, tests switched from async/ThrowsAsync to direct construction with assertions, naming aligned. Clean iteration.

Two observations:

1. Scope creep into existing exception tests (4 additional test files modified)

This PR originally adds 5 FileStore exception types, but now also rewrites all existing exception tests across Content/ExceptionTest.cs, Exceptions/ExceptionTest.cs, Registry/Exceptions/ExceptionTest.cs, and Registry/Remote/ExceptionTest.cs. While the new test style (direct construction + property assertions) is strictly better than the old ThrowsAsync pattern, bundling a codebase-wide test convention change with a feature PR makes it harder to review each concern independently. Consider splitting the existing test rewrites into a separate PR — "One logical change per PR."

2. PathTraversalDisallowedException line break (PathTraversalDisallowedException.cs:221-222)

nit: The class declaration splits the base type onto a separate line: public class PathTraversalDisallowedException / : UnauthorizedAccessException. This was flagged and resolved in the previous round for IOException, but now with UnauthorizedAccessException the line is public class PathTraversalDisallowedException : UnauthorizedAccessException which is 70 chars — fits on one line. The current split is still there. The other 4 exception classes keep the base type on the same line; this one should too for consistency.

Otherwise SGTM — all prior feedback addressed cleanly.

@akashsinghal akashsinghal left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. there is one small non blocking comment on line breaks

@akashsinghal akashsinghal added the ready-to-merge PR is ready to merge label Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-merge PR is ready to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants