Skip to content

Conversation

raravena80
Copy link

Summary

Fixes #207 - Resolves the issue where Modelfile parsing would fail with 'invalid args' error when file paths contained spaces without quotes.

Problem

When using auto-generated Modelfiles with file paths containing spaces (like CONFIG example workflows_Wan2.1/image_to_video_wan_480p_example.json), the parser would fail with:

Error: failed to parse modelfile: parse command line error on line X: invalid args

Solution

Modified the parseStringArgs() function in pkg/modelfile/parser/args_parser.go to:

  • Join multiple arguments with spaces instead of requiring exactly 1 argument
  • Handle unquoted paths like CONFIG path with spaces/file.json
  • Maintain full backward compatibility with quoted paths

Changes Made

  • Core Fix: Updated parseStringArgs() to use strings.Join(args, " ") for multiple arguments
  • Updated Tests: Modified existing tests and added comprehensive test coverage for edge cases
  • Fixed Integration Test: Updated modelfile integration test to reflect new expected behavior

Testing

All tests pass:

  • Unit tests: go test ./pkg/modelfile/parser/
  • Integration tests: go test ./pkg/modelfile/
  • Manual testing with comprehensive scenarios

Backward Compatibility:

  • Quoted paths still work: CONFIG "path with spaces/file.json"
  • Regular paths still work: CONFIG regular_file.json
  • Mixed usage in same Modelfile works

Example Usage

Before (would fail):

CONFIG example workflows_Wan2.1/image_to_video_wan_480p_example.json
# Error: parse command line error on line X: invalid args

After (now works):

# Both of these now work:
CONFIG example workflows_Wan2.1/image_to_video_wan_480p_example.json
CONFIG "example workflows_Wan2.1/image_to_video_wan_480p_example.json"

This makes auto-generated Modelfiles more robust and user-friendly while maintaining full backward compatibility.

Copy link

Summary of Changes

Hello @raravena80, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a crucial fix to the Modelfile parsing mechanism, specifically addressing an error that occurred when file paths containing unquoted spaces were used. By refining the argument parsing logic, the system can now correctly interpret such paths, significantly improving the robustness and user-friendliness of Modelfiles, especially those that are auto-generated. The changes maintain full backward compatibility and are thoroughly validated with updated test suites.

Highlights

  • Modelfile Parsing Fix: Resolved an issue where Modelfile parsing failed with 'invalid args' when file paths contained unquoted spaces, specifically addressing issue error when file name or path name has space in Modelfile #207.
  • Argument Handling Improvement: The parseStringArgs() function was modified to join multiple arguments with spaces, allowing unquoted paths like CONFIG path with spaces/file.json to be parsed correctly as a single argument.
  • Backward Compatibility: Ensured full backward compatibility for both quoted paths (e.g., CONFIG "path with spaces/file.json") and regular paths, making the system more robust without breaking existing functionality.
  • Enhanced Test Coverage: Updated existing tests and added new comprehensive test cases for edge cases, including specific scenarios for spaces in file paths, to validate the new parsing logic.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly addresses an issue with parsing Modelfile paths that contain spaces by joining arguments in parseStringArgs. The changes look good and the accompanying test updates are appropriate. I've added a couple of suggestions to further improve the robustness of the argument parsing. One suggestion is to enhance the validation to reject arguments that consist solely of whitespace. The other is to add more test cases to cover these whitespace-related edge cases. Overall, this is a solid fix.

Comment on lines 36 to 38
if joined == "" {
return nil, errors.New("empty args")
}

Choose a reason for hiding this comment

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

medium

The current check if joined == "" only handles cases where the argument is an empty string. It doesn't handle arguments that consist only of whitespace, such as " " or "" "". This could lead to creating nodes with paths that are just whitespace, which is likely undesirable.

To make the validation more robust, I suggest checking if the trimmed version of the joined string is empty. This will correctly reject arguments that are composed entirely of whitespace, while preserving any intentional whitespace in valid (quoted) arguments.

Suggested change
if joined == "" {
return nil, errors.New("empty args")
}
if strings.TrimSpace(joined) == "" {
return nil, errors.New("empty args")
}

Comment on lines 40 to 47
{[]string{"example", "workflows_Wan2.1/image_to_video_wan_480p_example.json"}, 13, 14, false, "example workflows_Wan2.1/image_to_video_wan_480p_example.json"},
}

Choose a reason for hiding this comment

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

medium

To improve test coverage and ensure correct handling of various whitespace scenarios, it would be beneficial to add a few more test cases. Specifically, we should test for:

  • Arguments that consist only of whitespace (e.g., " ").
  • Multiple empty string arguments (e.g., "" "").
  • Arguments with leading or trailing spaces that should be preserved.

These tests will help verify that whitespace-only arguments are rejected while intended whitespace in valid paths is preserved.

        {[]string{"example", "workflows_Wan2.1/image_to_video_wan_480p_example.json"}, 13, 14, false, "example workflows_Wan2.1/image_to_video_wan_480p_example.json"},
        // Test cases for whitespace handling
        {[]string{" "}, 15, 16, true, ""},
        {[]string{"", ""}, 17, 18, true, ""},
        {[]string{" a "}, 19, 20, false, " a "},
    }

Fixes issue #207 where Modelfile parsing would fail with 'invalid args' error
when file paths contained spaces without quotes.

Changes:
- Modified parseStringArgs() to join multiple arguments with spaces
- This handles unquoted paths like 'CONFIG example workflows/file.json'
- Maintains backward compatibility with quoted paths
- Updated tests to reflect new behavior
- Added comprehensive test coverage for edge cases

The fix allows both:
- CONFIG "path with spaces/file.json" (quoted - existing behavior)
- CONFIG path with spaces/file.json (unquoted - new behavior)

Signed-off-by: Ricardo Aravena <[email protected]>
…verage

Address feedback from @gemini-code-assist[bot] review:

1. Enhanced validation in parseStringArgs():
   - Use strings.TrimSpace() to reject arguments consisting solely of whitespace
   - Prevents creating nodes with whitespace-only paths
   - Maintains preservation of intentional whitespace in valid arguments

2. Added comprehensive test cases for whitespace handling:
   - Whitespace-only arguments (should be rejected)
   - Multiple empty string arguments (should be rejected)
   - Arguments with leading/trailing spaces (should be preserved)
   - Mixed whitespace scenarios

This improves robustness while maintaining backward compatibility and
the core functionality of handling unquoted paths with spaces.

Signed-off-by: Ricardo Aravena <[email protected]>
@raravena80 raravena80 force-pushed the fix-spaces-in-modelfile-paths branch from 697b901 to 2f68d85 Compare October 1, 2025 00:38
@chlins
Copy link
Member

chlins commented Oct 9, 2025

@raravena80 Thanks for your work! The original design is the value only includes one element, e.g, CONFIG foo, if it still needs a value, it should be a new line CONFIG bar. So I'm not sure whether we need to identify the issue as a new requirement.

@raravena80
Copy link
Author

@chlins that sounds like a new requirement. Do we have the multiple line requirement per config value defined in the spec? Also, sounds like we need a different set of test cases for that.

As long as we have the multiple line requirement well document imo it should be ok, we can't prevent users to put two different strings in a CONFIG line thinking that they are multiple different values.

Let me know what you think.

@chlins
Copy link
Member

chlins commented Oct 11, 2025

@chlins that sounds like a new requirement. Do we have the multiple line requirement per config value defined in the spec? Also, sounds like we need a different set of test cases for that.

As long as we have the multiple line requirement well document imo it should be ok, we can't prevent users to put two different strings in a CONFIG line thinking that they are multiple different values.

Let me know what you think.

@raravena80 So far, we have not received such requirement, and it seems that there is no such definition in the spec, because the modelfile is only a concept specific to the modctl tool itself and not a specification-defined term.

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.

error when file name or path name has space in Modelfile

2 participants