Skip to content

fix: widen GLMProvider import exception to catch ImportError (zhipuai<2.0)#240

Open
Jah-yee wants to merge 1 commit into
agentforce314:mainfrom
Jah-yee:main
Open

fix: widen GLMProvider import exception to catch ImportError (zhipuai<2.0)#240
Jah-yee wants to merge 1 commit into
agentforce314:mainfrom
Jah-yee:main

Conversation

@Jah-yee
Copy link
Copy Markdown

@Jah-yee Jah-yee commented Jun 2, 2026

Fix: widen GLMProvider import exception to catch ImportError

Problem

When is installed, from zhipuai import ZhipuAI raises a bare ImportError (not ModuleNotFoundError) because the ZhipuAI symbol was moved across major versions. The narrow except ModuleNotFoundError clause doesn't catch this, causing ClawcodexREPL(provider_name='glm') to crash at import time.

Fix

Widen the exception clause from ModuleNotFoundError to ImportError (its superclass), which catches both:

  • ModuleNotFoundError — zhipuai not installed
  • ImportError — zhipuai installed but ZhipuAI symbol not found (e.g. zhipuai<2.0)

Fixes #166.

Verification

python3 -m py_compile src/providers/glm_provider.py

Diff

-    except ModuleNotFoundError:  # pragma: no cover
+    except ImportError:  # catches both ModuleNotFoundError and bare ImportError (e.g. zhipuai<2.0 where ZhipuAI symbol moved)

…<2.0)

When zhipuai<2.0 is installed, 'from zhipuai import ZhipuAI' raises
ImportError (not ModuleNotFoundError) because the ZhipuAI symbol moved
across major versions. The narrow 'except ModuleNotFoundError' clause
does not catch this, causing ClawcodexREPL(provider_name='glm') to crash
at import time.

Widen to 'except ImportError' which covers both cases.
Fixes agentforce314#166.
@Jah-yee
Copy link
Copy Markdown
Author

Jah-yee commented Jun 2, 2026

Happy to help widen the exception handler! GLMProvider should handle both ModuleNotFoundError and ImportError for zhipuai versions < 2.0 — this is a clean one-line fix.

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.

GLMProvider import crashes on zhipuai<2.x — except clause too narrow

1 participant