Skip to content

refactor(file): return option from extraction format parsing#10411

Merged
jdx merged 1 commit into
jdx:mainfrom
risu729:refactor/extraction-format-from-ext-option
Jun 13, 2026
Merged

refactor(file): return option from extraction format parsing#10411
jdx merged 1 commit into
jdx:mainfrom
risu729:refactor/extraction-format-from-ext-option

Conversation

@risu729

@risu729 risu729 commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Summary

  • change ExtractionFormat::from_ext to return Option<ExtractionFormat> instead of silently falling back to Raw
  • keep filename detection and legacy explicit-format callers falling back to Raw where they already did
  • simplify Java metadata format handling by using and_then for recognized file types

Tests

  • cargo fmt
  • cargo test test_extraction_format_from_file_name
  • cargo test effective_extraction_format
  • cargo check

Summary by CodeRabbit

  • Bug Fixes
    • Improved archive format detection to gracefully handle unsupported or unrecognized file formats by defaulting to raw extraction mode instead of failing, enhancing compatibility with various archive types.

@coderabbitai

coderabbitai Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: cedd2ad5-1a8a-4f5f-9b62-9a529824eaa3

📥 Commits

Reviewing files that changed from the base of the PR and between 956765a and 172d3ae.

📒 Files selected for processing (5)
  • src/backend/aqua.rs
  • src/backend/github.rs
  • src/backend/static_helpers.rs
  • src/file.rs
  • src/plugins/core/java.rs

📝 Walkthrough

Walkthrough

This PR refactors the ExtractionFormat::from_ext method to return Option<Self> instead of Self, treating unknown file extensions as parse failures rather than defaulting to Raw. The change is coordinated across all callers in backends and plugins, which explicitly default to Raw where appropriate. The tar-pattern detection logic in from_file_name is updated to use the new optional API.

Changes

Extraction Format API Refactor

Layer / File(s) Summary
Core API change and tar-pattern refactoring
src/file.rs
ExtractionFormat::from_ext signature changes from -> Self to -> Option<Self>, returning None for unknown extensions. ExtractionFormat::from_file_name is rewritten to detect ".tar.*" patterns via the optional from_ext, then falls back to the final path extension with Raw as default. Unit tests updated to expect Option returns for both known and unknown extensions.
Caller updates for optional from_ext
src/backend/aqua.rs, src/backend/github.rs, src/backend/static_helpers.rs, src/plugins/core/java.rs
All callers of ExtractionFormat::from_ext updated to handle Option return: aqua.rs uses unwrap_or(Raw) in validation logic, github.rs and static_helpers.rs default to Raw on parse failure, and java.rs uses and_then(from_ext) in the format derivation chain.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • jdx/mise#10403: Both PRs touch src/file.rs's ExtractionFormat parsing—main PR refactors from_ext to return Option, while the related PR adds the tbz alias and updates from_ext("tbz") expectations.
  • jdx/mise#10409: Both PRs modify ExtractionFormat::from_ext behavior and its use in src/backend/aqua.rs::effective_extraction_format to control how unsupported aqua formats are handled.
  • jdx/mise#10275: The main PR's extraction-format parsing refactor overlaps directly with retrieval of how aqua and archive-format selection logic is updated across aqua.rs, github.rs, and static_helpers.rs.

Poem

🐰 From Self to Option we hop with grace,
Tar patterns shine in their special place,
Unknown extensions now return None,
Callers unwrap them—refactoring done!
No more guessing, just explicit care,
The format flows through with crystal air. 🎀

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.22% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and specifically describes the primary change: refactoring ExtractionFormat::from_ext to return Option instead of a concrete value, which is the core API change across multiple files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@risu729 risu729 marked this pull request as ready for review June 13, 2026 21:06
@greptile-apps

greptile-apps Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR refactors ExtractionFormat::from_ext to return Option<ExtractionFormat> instead of silently falling back to Raw for unrecognized extensions, making parse failure explicit at every call site.

  • src/file.rs: from_ext now uses .parse().ok() returning Option<Self>; from_file_name updated to use if let Some and a terminal .unwrap_or(Raw).
  • src/backend/aqua.rs: The "raw" entry is correctly dropped from the format exception list since \"raw\" now parses to Some(Raw) rather than needing special-casing.
  • src/plugins/core/java.rs: .map(from_ext).filter(|f| *f != Raw) simplified to .and_then(from_ext); semantically equivalent because the upstream java_file_type_supported filter ensures only \"zip\", \"tar.gz\", and \"tar.xz\" reach the install path.

Confidence Score: 5/5

All call sites correctly handle the new Option return and preserve their pre-existing fallback-to-Raw semantics; no behavior change for any known format string.

Each call site was updated consistently: aqua bails on unknown formats (unchanged), github and static_helpers fall back to Raw for unrecognized explicit options (unchanged), and Java's and_then replacement is functionally identical for the file types that can actually reach that code. The "raw" exception removal from the aqua allow-list is sound because "raw" parses to a concrete variant. Tests cover the changed paths.

No files require special attention.

Important Files Changed

Filename Overview
src/file.rs Core change: from_ext now returns Option<Self> instead of always returning Raw on parse failure; from_file_name updated accordingly. Logic is correctly preserved.
src/backend/aqua.rs Removes "raw" from the exception list in effective_extraction_format; correct because "raw" now parses to Some(Raw) so is_none() is never true for it.
src/backend/github.rs Adds explicit .unwrap_or(Raw) for unrecognized explicit format options, preserving the legacy silent-fallback behavior.
src/backend/static_helpers.rs Same pattern as github.rs: explicit .unwrap_or(Raw) for the format option path, legacy behavior preserved.
src/plugins/core/java.rs Replaces `.map(from_ext).filter(

Reviews (1): Last reviewed commit: "refactor(file): return option from extra..." | Re-trigger Greptile

@risu729 risu729 marked this pull request as draft June 13, 2026 21:13
@risu729 risu729 marked this pull request as ready for review June 13, 2026 21:14
@jdx jdx merged commit 38a039c into jdx:main Jun 13, 2026
33 checks passed
@risu729 risu729 deleted the refactor/extraction-format-from-ext-option branch June 13, 2026 21:54
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