Skip to content

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

Merged
ericleepi314 merged 1 commit into
agentforce314:mainfrom
Jah-yee:main
Jun 3, 2026
Merged

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

Conversation

@Jah-yee

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

Copy link
Copy Markdown
Contributor

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

Jah-yee commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

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.

@ericleepi314
ericleepi314 merged commit 42b8a4f into agentforce314:main Jun 3, 2026
singlaamitesh pushed a commit to singlaamitesh/clawcodex that referenced this pull request Jul 7, 2026
fix: widen GLMProvider import exception to catch ImportError (zhipuai<2.0)
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

2 participants