Skip to content

Validate --pluginassembly at parse time with a native FileInfo option#792

Merged
ptr727 merged 5 commits into
developfrom
feature/cli-path-validation
Jul 1, 2026
Merged

Validate --pluginassembly at parse time with a native FileInfo option#792
ptr727 merged 5 commits into
developfrom
feature/cli-path-validation

Conversation

@ptr727

@ptr727 ptr727 commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Summary

Follow-up to #791. Converts the --pluginassembly option from string to a native Option<FileInfo> with AcceptExistingOnly(), so a missing plugin path fails at argument parsing with a clear File does not exist message before the command handler runs.

This lets PluginLoader.Load take a FileInfo and drop its manual validation — the empty-path check, Path.GetFullPath, and File.Exists guards are removed (the CLI now guarantees an existing, resolved path). The remaining try/catch covers genuine assembly-load/reflection errors only.

Scope

Deliberately limited to --pluginassembly, the one path option that is a pure input whose validation this actually removes:

  • --mediafilesGetFiles still needs its try/catch for enumeration/permission/cancellation, so a native type would only add a FileSystemInfostring conversion without removing code (and the collection AcceptExistingOnly support is inconsistent). Left as List<string>.
  • --settingsfile / --schemafile — write paths for defaultsettings/createschema, so must-exist would be wrong. Unchanged.

Testing

  • Build clean (0 warnings, TreatWarningsAsErrors), format clean, full suite green (162).
  • Parse-time validation verified: --pluginassembly /no/such.dllFile does not exist: '/no/such.dll'., exit 1, before the handler.
  • Happy path verified end to end: the example plugin loads and runs (exit 0).

No version bump (part of unreleased 3.20).

Use Option<FileInfo> with AcceptExistingOnly so a missing plugin path fails at
argument parsing with a clear "File does not exist" message before the command
runs, and simplify PluginLoader.Load to take a FileInfo and drop the empty-path,
GetFullPath, and File.Exists guards (the CLI now guarantees an existing path).

Scope is limited to --pluginassembly, the one path option that is a pure input
whose validation this removes; --mediafiles/--settingsfile/--schemafile keep
their current handling.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 1, 2026 18:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Updates PlexCleaner’s custom plugin command to validate --pluginassembly at argument-parse time (instead of inside the handler) by switching the option to a native FileInfo with AcceptExistingOnly(), and adjusts the plugin loader/tests accordingly.

Changes:

  • Convert --pluginassembly from string to Option<FileInfo> and enable parse-time existence validation via AcceptExistingOnly().
  • Update PluginLoader.Load to accept a FileInfo and remove the prior manual path validation.
  • Update plugin loader tests and add a defensive null-check in CustomCommand for the bound option.

Reviewed changes

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

File Description
PlexCleaner/CommandLineOptions.cs Changes --pluginassembly to Option<FileInfo> and applies AcceptExistingOnly(); binds to CommandLineOptions.PluginAssembly as FileInfo?.
PlexCleaner/PluginLoader.cs Updates PluginLoader.Load signature to accept FileInfo and removes manual path validation logic.
PlexCleaner/Program.cs Adds a null guard before calling PluginLoader.Load in the custom command handler.
PlexCleanerTests/PluginLoaderTests.cs Updates tests to pass FileInfo into PluginLoader.Load.

Comment thread PlexCleaner/PluginLoader.cs Outdated
FileInfo.FullName resolves the path and can throw on a malformed or too-long
path; move it inside the try so any error is logged via LogAndHandle and returns
null instead of throwing, and log the file name in the catch since it does not
resolve the path.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

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 4 out of 4 changed files in this pull request and generated 3 comments.

Comment thread PlexCleaner/PluginLoader.cs
Comment thread PlexCleaner/Program.cs
Comment thread PlexCleaner/CommandLineOptions.cs
- PluginLoader.Load: guard against a null FileInfo with ArgumentNullException so
  the catch block never dereferences a null argument
- CustomCommand: log an explicit error before returning when the plugin path is
  missing so the failure is visible even though the option is required
- CommandLineTests: cover the custom command, an existing plugin path binds and
  a missing path fails at parse time via AcceptExistingOnly

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

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 5 out of 5 changed files in this pull request and generated 2 comments.

Comment thread PlexCleaner/PluginLoader.cs
Comment thread PlexCleaner/PluginLoader.cs Outdated
Track the assembly path in a single variable that starts as the file name and
upgrades to the resolved full path inside the try, so the catch logs the most
specific location available (full path when resolved, file name if FullName
threw) instead of only the ambiguous file name.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

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 5 out of 5 changed files in this pull request and generated 1 comment.

Comment thread PlexCleaner/CommandLineOptions.cs
AcceptExistingOnly was applied unconditionally, so under an AOT build a
non-existent plugin path would fail at parse instead of reaching CustomCommand
and its "requires a non-AOT build" message. Gate both Required and
AcceptExistingOnly behind PLUGINS, matching the command handler.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

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 5 out of 5 changed files in this pull request and generated no new comments.

@ptr727 ptr727 merged commit cda3283 into develop Jul 1, 2026
13 checks passed
@ptr727 ptr727 deleted the feature/cli-path-validation branch July 1, 2026 18:30
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