Commit 7b452e6
authored
fix(llm): surface tool-call errors via sendMessage (#1169)
## Description
`useLLM` with `toolsConfig` silently dropped errors from the
tool-execution path: `parseToolCall` swallowed every parse failure with
`Logger.error`, and `LLMController.sendMessage` fired
`executeToolCallback` without `await` or `.catch`. Neither `llm.error`
nor the caller's `await llm.sendMessage(...)` `try/catch` ever saw them.
This PR makes those errors propagate:
- `parseToolCall` now distinguishes "no tool call in output" (returns
`[]` — the model legitimately chose not to call a tool) from "malformed
tool-call JSON" (throws `RnExecutorchError(InvalidModelOutput)`).
- `LLMController.sendMessage` `await`s `executeToolCallback` inside
`try/catch` and rethrows via `parseUnknownError`, so failures reach the
caller's `try/catch` (and the hook's `error` state if wired).
### Introduces a breaking change?
- [x] Yes
- [ ] No
Callers of `parseToolCall` that previously received `[]` for malformed
tool-call JSON now get a thrown `RnExecutorchError(InvalidModelOutput)`.
Same applies to `sendMessage` when `toolsConfig` is set and the tool
path throws — the error now surfaces instead of being silently
swallowed.
### Type of change
- [x] Bug fix (change which fixes an issue)
- [ ] New feature (change which adds functionality)
- [ ] Documentation update (improves or adds clarity to existing
documentation)
- [ ] Other (chores, tests, code style improvements etc.)
### Tested on
- [x] iOS
- [ ] Android
### Testing instructions
1. Open the `llm` demo app → **Tool calling** screen.
2. Switch the picker to a non-tool-trained model (e.g. Llama 3.2 1B
QLoRA / SpinQuant).
3. Send a tool-shaped prompt (`What events do I have today?`).
4. If the tool-execution path throws (e.g. "max recursion depth reached"
on tool-naive models, malformed tool-call JSON), the on-screen
`ErrorBanner` now displays the error instead of staying empty.
5. Sanity check on a tool-trained model (Hammer 2.1 1.5B): tool calls
still execute normally and no error banner appears.
### Related issues
Fixes #1157
### Checklist
- [x] I have performed a self-review of my code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have updated the documentation accordingly
- [x] My changes generate no new warnings1 parent 00422ef commit 7b452e6
2 files changed
Lines changed: 51 additions & 38 deletions
Lines changed: 14 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
416 | 416 | | |
417 | 417 | | |
418 | 418 | | |
419 | | - | |
420 | | - | |
421 | | - | |
422 | | - | |
423 | | - | |
424 | | - | |
425 | | - | |
426 | | - | |
427 | | - | |
428 | | - | |
429 | | - | |
430 | | - | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
431 | 433 | | |
432 | 434 | | |
433 | 435 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
13 | | - | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
14 | 20 | | |
15 | 21 | | |
16 | 22 | | |
17 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
18 | 30 | | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
25 | 39 | | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
39 | 53 | | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | 54 | | |
| 55 | + | |
| 56 | + | |
46 | 57 | | |
47 | 58 | | |
48 | 59 | | |
| |||
0 commit comments