Skip to content

Comments

fix: validate REME env vars before launching to prevent TypeError#37

Open
haosenwang1018 wants to merge 2 commits intomodelscope:mainfrom
haosenwang1018:fix/validate-reme-env-vars
Open

fix: validate REME env vars before launching to prevent TypeError#37
haosenwang1018 wants to merge 2 commits intomodelscope:mainfrom
haosenwang1018:fix/validate-reme-env-vars

Conversation

@haosenwang1018
Copy link

Problem

Running python launcher.py --with-reme without REME_PATH and REME_SCRIPT in the environment crashes with a cryptic TypeError: sequence item 0: expected str instance, NoneType found deep in daemon.py during hash computation.

Fixes #9

Fix

Add early validation in pty_launch() that checks whether the required environment variables are set. If missing, raises EnvironmentError with a clear message listing which variables need to be defined.

Changes

  • launcher.py: Validate {SERVICE}_PATH and {SERVICE}_SCRIPT env vars before use

When REME_PATH or REME_SCRIPT are not set in the environment,
pty_launch() passes None values to LaunchCommandWhenAbsent, which
crashes with TypeError during hash computation.

Add early validation with a clear error message listing which
variables are missing, instead of a cryptic TypeError deep in
the daemon module.

Fixes modelscope#9
@gemini-code-assist
Copy link

Summary of Changes

Hello @haosenwang1018, 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 addresses a critical issue where the application would crash with an unhelpful TypeError if required environment variables (REME_PATH, REME_SCRIPT) were not set. The changes introduce robust early validation within the pty_launch function, ensuring that these variables are present before proceeding. If any are missing, a descriptive EnvironmentError is now raised, providing immediate and actionable feedback to the user, significantly improving the developer experience and preventing runtime failures.

Highlights

  • Error Prevention: Implemented early validation for _PATH and _SCRIPT environment variables in pty_launch() to prevent a TypeError when they are undefined.
  • Improved Error Messaging: Replaced a cryptic TypeError with a clear EnvironmentError that specifies which environment variables are missing, guiding users to define them.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • launcher.py
    • Added validation for required environment variables ({SERVICE}_PATH and {SERVICE}_SCRIPT) before their use in pty_launch.
Activity
  • No specific activity has been recorded for this pull request yet.
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

The pull request effectively addresses the issue where missing environment variables caused a cryptic TypeError during the launch process. By adding early validation in pty_launch, the code now provides a clear and actionable error message for all services. This is a significant improvement to the robustness and user experience of the launcher. I have suggested using RuntimeError instead of the legacy EnvironmentError to align with modern Python practices. Note that the hardcoded tag in the service launch logic (line 116) may cause log collisions for non-appworld services and should be addressed separately.

launcher.py Outdated
if not service_path or not service_script:
missing = [v for v in (path_var, script_var)
if not os.environ.get(v)]
raise EnvironmentError(

Choose a reason for hiding this comment

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

medium

In Python 3, EnvironmentError is a legacy alias for OSError. For configuration or pre-condition errors like this, RuntimeError is generally more idiomatic as it indicates a failure to meet the requirements for execution. This change improves maintainability by following modern Python standards.

Suggested change
raise EnvironmentError(
raise RuntimeError(

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.

Launcher crashes when REME_PATH/REME_SCRIPT are unset

1 participant