Skip to content

bug fix when parameter model_dir is wrongly provided - #619

Merged
ypriverol merged 4 commits into
bigbio:devfrom
ypriverol:dev
Dec 3, 2025
Merged

ypriverol merged 4 commits into
bigbio:devfrom
ypriverol:dev

Conversation

@ypriverol

@ypriverol ypriverol commented Dec 2, 2025 •

Copy link
Copy Markdown
Contributor

User description

PR checklist

  • This comment contains a description of changes (with reason).
  • If you've fixed a bug or added code that should be tested, add tests!
  • If you've added a new tool - have you followed the pipeline conventions in the contribution docs
  • If necessary, also make a PR on the bigbio/quantms branch on the nf-core/test-datasets repository.
  • Make sure your code lints (nf-core pipelines lint).
  • Ensure the test suite passes (nextflow run . -profile test,docker --outdir <OUTDIR>).
  • Check for unexpected warnings in debug mode (nextflow run . -profile debug,test,docker --outdir <OUTDIR>).
  • Usage Documentation in docs/usage.md is updated.
  • Output Documentation in docs/output.md is updated.
  • CHANGELOG.md is updated.
  • README.md is updated (including new tool citations and authors/contributors).

PR Type

Bug fix


Description

  • Fix parameter validation for ms2features_model_dir to handle edge cases

  • Prevent passing invalid values (empty strings, boolean true, whitespace)

  • Add robust null and type checking before constructing command argument


Diagram Walkthrough

flowchart LR
  A["Parameter Input"] --> B["Validate Not Null/True"]
  B --> C["Convert to String & Trim"]
  C --> D["Check Non-Empty & Not 'true'"]
  D --> E["Build Command Argument"]
  D --> F["Skip Argument"]
Loading

File Walkthrough

Relevant files
Bug fix
main.nf
Enhance ms2features_model_dir parameter validation             

modules/local/utils/msrescore_features/main.nf

  • Replaced simple ternary operator with comprehensive parameter
    validation logic
  • Added null check and boolean true detection to prevent invalid
    parameter values
  • Implemented string conversion and trimming to handle whitespace edge
    cases
  • Added lowercase comparison to catch string "true" values
+10/-1   

@coderabbitai

coderabbitai Bot commented Dec 2, 2025 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@qodo-code-review

qodo-code-review Bot commented Dec 2, 2025 •

Copy link
Copy Markdown
Contributor

PR Compliance Guide 🔍

Below is a summary of compliance checks for this PR:

Security Compliance
🟢
No security concerns identified No security vulnerabilities detected by AI analysis. Human verification advised for critical code.
Ticket Compliance
⚪
🎫 No ticket provided
  • Create ticket/issue
Codebase Duplication Compliance
⚪
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
Generic: Meaningful Naming and Self-Documenting Code

Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Error Handling

Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Logging Practices

Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Security-First Input Validation and Data Handling

Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

⚪
Generic: Comprehensive Audit Trails

Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.

Status:
No audit logs: The new parameter validation logic adds or skips a command argument without emitting any
audit log about the decision, which may hinder reconstructing configuration-driven
actions.

Referred Code
// Only add ms2_model_dir if it's actually set and not empty
// Handle cases where parameter might be empty string, null, boolean true, or whitespace
// When --ms2features_model_dir is passed with no value, Nextflow may set it to boolean true
def ms2_model_dir = ""
if (params.ms2features_model_dir != null && params.ms2features_model_dir != true) {
    def model_dir_str = params.ms2features_model_dir.toString().trim()
    if (model_dir_str && model_dir_str.toLowerCase() != "true") {
        ms2_model_dir = "--ms2_model_dir ${model_dir_str}"
    }
}

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Robust Error Handling and Edge Case Management

Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation

Status:
Missing error path: While edge cases are filtered out, there is no explicit error or warning when an invalid
ms2features_model_dir is provided, potentially causing silent misconfiguration.

Referred Code
if (params.ms2features_model_dir != null && params.ms2features_model_dir != true) {
    def model_dir_str = params.ms2features_model_dir.toString().trim()
    if (model_dir_str && model_dir_str.toLowerCase() != "true") {
        ms2_model_dir = "--ms2_model_dir ${model_dir_str}"
    }

Learn more about managing compliance generic rules or creating your own custom rules

  • Update
Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

@ypriverol ypriverol changed the title Dev bug fix when parameter model_dir is wrongly provided Dec 2, 2025
@qodo-code-review

qodo-code-review Bot commented Dec 2, 2025 •

Copy link
Copy Markdown
Contributor

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
✅ Simplify parameter validation logic
Suggestion Impact:The commit simplified the parameter handling into a single conditional expression, removing nested ifs, aligning with the suggestion’s goal of simplification (though it used a ternary rather than the exact proposed code).

code diff:

-    def ms2_model_dir = ""
-    if (params.ms2features_model_dir != null && params.ms2features_model_dir != true) {
-        def model_dir_str = params.ms2features_model_dir.toString().trim()
-        if (model_dir_str && model_dir_str.toLowerCase() != "true") {
-            ms2_model_dir = "--ms2_model_dir ${model_dir_str}"
-        }
-    }
+    def ms2_model_dir = (params.ms2features_model_dir && params.ms2features_model_dir != true) ? "--ms2_model_dir ${params.ms2features_model_dir}" : ""

Simplify the parameter validation logic by using the safe navigation operator
(?.) and a single if condition to replace the nested checks.

modules/local/utils/msrescore_features/main.nf [31-37]

 def ms2_model_dir = ""
-if (params.ms2features_model_dir != null && params.ms2features_model_dir != true) {
-    def model_dir_str = params.ms2features_model_dir.toString().trim()
-    if (model_dir_str && model_dir_str.toLowerCase() != "true") {
-        ms2_model_dir = "--ms2_model_dir ${model_dir_str}"
-    }
+def model_dir_str = params.ms2features_model_dir?.toString().trim()
+if (model_dir_str && model_dir_str.toLowerCase() != 'true') {
+    ms2_model_dir = "--ms2_model_dir ${model_dir_str}"
 }

[Suggestion processed]

Suggestion importance[1-10]: 5

__

Why: The suggestion correctly refactors the nested if statements into a more concise and readable block using the safe navigation operator, which improves code quality.

Low
  • Update

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 fixes parameter validation for ms2features_model_dir to prevent invalid values (empty strings, boolean true, or whitespace) from being passed to the ms2rescore command. The fix replaces a simple ternary operator with comprehensive validation logic that checks for null, boolean true, empty strings, and whitespace before constructing the command argument.

Key Changes

  • Enhanced parameter validation with explicit null and boolean true checks
  • Added string trimming and empty string detection to handle edge cases
  • Included detailed comments explaining the validation logic

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ypriverol
ypriverol merged commit 6e4c0d8 into bigbio:dev Dec 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants