Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: clap cannot downcast CLI flags to PathBuf #1096

Merged
merged 1 commit into from
Feb 18, 2025

Conversation

jvanz
Copy link
Member

@jvanz jvanz commented Feb 18, 2025

Description

After the recent changes clap is not able to cast the CLI flags into PathBuf type. To fix that, we can configure the value parser when the Arg is created.

This is causing errors when running CI on Kubewarden controller main branch and kubewarden/kubewarden-controller#1007

KUBEWARDEN_CERT_FILE="tls.crt" KUBEWARDEN_KEY_FILE="tls.key" KUBEWARDEN_POLICIES_DOWNLOAD_DIR=/tmp KUBEWARDEN_POLICIES=policies.yml.example KUBEWARDEN_LOG_LEVEL=debug KUBEWARDEN_SIGSTORE_CACHE_DIR="/tmp/sigstore-data" KUBEWARDEN_ALWAYS_ACCEPT_ADMISSION_REVIEWS_ON_NAMESPACE="kubewarden" KUBEWARDEN_CLIENT_CA_FILE="ca.crt" cargo run
thread 'main' panicked at src/config.rs:193:29:
Mismatch between definition and access of `cert-file`. Could not downcast to std::path::PathBuf, need to downcast to alloc::string::String

stack backtrace:
   0: rust_begin_unwind
             at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/std/src/panicking.rs:665:5
   1: core::panicking::panic_fmt
             at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/core/src/panicking.rs:74:14
   2: clap_builder::parser::error::MatchesError::unwrap
             at /home/jvanz/.cargo/registry/src/index.crates.io-6f17d22bba15001f/clap_builder-4.5.30/src/parser/error.rs:32:9
   3: clap_builder::parser::matches::arg_matches::ArgMatches::get_one
             at /home/jvanz/.cargo/registry/src/index.crates.io-6f17d22bba15001f/clap_builder-4.5.30/src/parser/matches/arg_matches.rs:119:9
   4: policy_server::config::build_tls_config
             at ./src/config.rs:193:21
   5: policy_server::config::Config::from_args

Test

KUBEWARDEN_CERT_FILE="tls.crt" KUBEWARDEN_KEY_FILE="tls.key" KUBEWARDEN_POLICIES_DOWNLOAD_DIR=/tmp KUBEWARDEN_POLICIES=policies.yml.example KUBEWARDEN_LOG_LEVEL=debug KUBEWARDEN_SIGSTORE_CACHE_DIR="/tmp/sigstore-data" KUBEWARDEN_ALWAYS_ACCEPT_ADMISSION_REVIEWS_ON_NAMESPACE="kubewarden" KUBEWARDEN_CLIENT_CA_FILE="ca.crt" cargo run

After the recent changes clap is not able to cast the CLI flags into
PathBuf type. To fix that, we can configure the value parser when the
Arg is created.

Signed-off-by: José Guilherme Vanz <jguilhermevanz@suse.com>
@jvanz jvanz added this to the 1.22 milestone Feb 18, 2025
@jvanz jvanz self-assigned this Feb 18, 2025
@jvanz jvanz requested a review from a team as a code owner February 18, 2025 16:58
Copy link

codecov bot commented Feb 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 59.57%. Comparing base (aecaeba) to head (5f206a6).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1096      +/-   ##
==========================================
- Coverage   59.81%   59.57%   -0.25%     
==========================================
  Files          18       18              
  Lines        1217     1217              
==========================================
- Hits          728      725       -3     
- Misses        489      492       +3     
Flag Coverage Δ
integration-tests 51.03% <ø> (-0.25%) ⬇️
unit-tests 35.47% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

Copy link
Contributor

@fabriziosestito fabriziosestito left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for fixing this

@jvanz jvanz merged commit 6d89a57 into kubewarden:main Feb 18, 2025
15 of 16 checks passed
@jvanz jvanz deleted the fix-clap-downcast branch February 18, 2025 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants