Skip to content

fix: type error when constructing RepublicError on error#167

Merged
frostming merged 1 commit intobubbuild:mainfrom
piglei:fix-errmsg-wont-show-type-error
Apr 13, 2026
Merged

fix: type error when constructing RepublicError on error#167
frostming merged 1 commit intobubbuild:mainfrom
piglei:fix-errmsg-wont-show-type-error

Conversation

@piglei
Copy link
Copy Markdown
Contributor

@piglei piglei commented Apr 13, 2026

Bub won't report the error message on error, the stack trace:

  File "/home/ubuntu/bub/bub/src/bub/framework.py", line 149, in _run_model
    await self._hook_runtime.notify_error(
          │    │             └ <function HookRuntime.notify_error at 0x70a8adf11580>
          │    └ <bub.hook_runtime.HookRuntime object at 0x70a8ae72db20>
          └ <bub.framework.BubFramework object at 0x70a8adf19b20>

> File "/home/ubuntu/bub/bub/src/bub/hook_runtime.py", line 82, in notify_error
    await value
          └ <coroutine object BuiltinImpl.on_error at 0x70a8a7f288c0>

  File "/home/ubuntu/bub/bub/src/bub/builtin/hook_impl.py", line 157, in on_error
    content=f"An error occurred at stage '{stage}': {error}",
                                           │         └ RepublicError(kind='invalid_input', message="openrouter:kimi-k2.5: Error code: 400 - {'id': 'e2d7e711df0a3f112f0bc51ded289ea7...
                                           └ 'run_model'

  File "/home/ubuntu/bub/bub/.venv/lib/python3.12/site-packages/republic/core/errors.py", line 31, in __str__
    return f"[{self.kind.value}] {self.message}"
               │    │             │    └ "openrouter:kimi-k2.5: Error code: 400 - {'id': 'e2d7e711df0a3f112f0bc51ded289ea7', 'error': {'message': 'Request parameters ...
               │    │             └ RepublicError(kind='invalid_input', message="openrouter:kimi-k2.5: Error code: 400 - {'id': 'e2d7e711df0a3f112f0bc51ded289ea7...
               │    └ 'invalid_input'
               └ RepublicError(kind='invalid_input', message="openrouter:kimi-k2.5: Error code: 400 - {'id': 'e2d7e711df0a3f112f0bc51ded289ea7...

AttributeError: 'str' object has no attribute 'value'

The reason is that the exception instance was created with "kind" using the wrong type, a str instead of the enum.

This PR fixes this issue by updating the construction statement for the RepublicError type when an error occurs. Another possible solution would be to modify the RepublicError type to accept a raw string type for the "kind" field and do the type conversion inside. Please let me know if this makes more sense.

@frostming frostming merged commit cc2226b into bubbuild:main Apr 13, 2026
5 checks passed
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.

2 participants