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

[Hot Fix] Add ImportErrorReporter to optimize the error message when packages are missing #224

Merged
merged 2 commits into from
May 14, 2024

Conversation

pan-x-c
Copy link
Collaborator

@pan-x-c pan-x-c commented May 14, 2024

Description

As the title says.

Checklist

Please check the following items before code is ready to be reviewed.

  • Code has passed all tests
  • Docstrings have been added/updated in Google Style
  • Documentation has been updated
  • Code is ready for review

@pan-x-c pan-x-c added enhancement New feature or request ready for review labels May 14, 2024
@garyzhang99
Copy link
Collaborator

garyzhang99 commented May 14, 2024

The current implementation method of grouping multiple module imports together within a try catch block can lead to incorrect error reporting. For example, if I have not installed gRPC:

try:
    import dill
    import grpc
    from grpc import ServicerContext
    from expiringdict import ExpiringDict
except ImportError:
    from agentscope.utils.tools import ImportErrorReporter

    dill = ImportErrorReporter("dill", "distribute")
    grpc = ImportErrorReporter("grpcio", "distribute")
    ServicerContext = ImportErrorReporter("grpcio", "distribute")
    ExpiringDict = ImportErrorReporter("expiringdict", "distribute")

Under these circumstances, an error related to dill would be reported.

Possible solutions or workarounds include:

  • Separating each import with its own try-except block, which solves the issue but makes the import section of the code lengthy.
  • Modifying the error messages?

@pan-x-c
Copy link
Collaborator Author

pan-x-c commented May 14, 2024

Now use the error message of the original ImportError.

Copy link
Collaborator

@garyzhang99 garyzhang99 left a comment

Choose a reason for hiding this comment

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

LGTM

@pan-x-c pan-x-c merged commit aaf672c into modelscope:main May 14, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants