Commit 95b8b14
Host callable errors (#3680)
When a host function called from BAML throws an error, we can take one
of three paths:
1. If the error type violates the BAML error type contract, then a
`HostContractViolation` panic is raised in BAML
2. If the error type is convertible into a BAML type (e.g. codegenned
type or primitive) then it is raised in BAML
3. Otherwise the error type is not convertible and is saved to the host
value table. The handle to it wrapped in a `HostCallable` BAML error
which is thrown in BAML. If the `HostCallable` is returned back out to
the host then it will get the value from the table.
This also includes making sysop errors properly catchable: previously
all sysop errors were just converted into fatal internal engine errors.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Native host exceptions can round-trip and be rehydrated by SDKs;
Node/Python SDKs expose registry/lookup helpers to preserve original
Error identity.
* Typed host-throws supported and a new HostContractViolation panic
reports host contract mismatches.
* **Bug Fixes**
* IO/env/filesystem/http errors now surface clearer categories (e.g.,
InvalidArgument, ParseError) for non-UTF‑8 and invalid inputs.
* Async/bridge error paths unified so thrown payloads, tracebacks, and
error propagation behave more consistently.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Sam Lijin <sam@boundaryml.com>1 parent d00da2b commit 95b8b14
92 files changed
Lines changed: 6446 additions & 3714 deletions
File tree
- baml_language
- crates
- baml_builtins2_codegen/src
- baml_builtins2/baml_std/baml
- ns_env
- ns_errors
- ns_fs
- ns_host
- ns_panics
- baml_cli/src/snapshots
- baml_lsp_server/src
- baml_tests
- snapshots
- baml_src
- compiles/__baml_std__
- src/compiler2_tir/snapshots
- tests
- bytecode_format/snapshots
- bex_engine
- src
- tests
- bex_external_types/src
- bex_resource_types/src
- bex_vm_types
- src
- bex_vm/src
- bridge_cffi/src/ffi
- bridge_ctypes
- src
- types/baml_core/cffi/v1
- bridge_wasm
- src
- tests
- sys_llm/src
- types
- sys_native/src
- ops
- sys_ops/src
- sys_types/src
- sdk_tests
- crates
- python_pydantic2/function_calls/customizable
- typescript_node/function_calls/customizable
- fixtures/function_calls/baml_src/ns_host_callable_tests
- sdks
- go/bridge_go/cffi/proto/baml_core/cffi/v1
- nodejs/bridge_nodejs
- dist
- proto
- src
- tests
- typescript_src
- proto
- python
- rust/bridge_python/src
- src/baml_core
- cffi/v1
- tests
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
265 | 265 | | |
266 | 266 | | |
267 | 267 | | |
| 268 | + | |
268 | 269 | | |
269 | 270 | | |
270 | 271 | | |
| |||
Lines changed: 5 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
3 | 7 | | |
4 | 8 | | |
5 | 9 | | |
| |||
Lines changed: 11 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | 53 | | |
59 | 54 | | |
60 | 55 | | |
61 | 56 | | |
62 | 57 | | |
63 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
64 | 69 | | |
65 | 70 | | |
66 | 71 | | |
| |||
Lines changed: 18 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
2 | 6 | | |
3 | 7 | | |
4 | 8 | | |
5 | 9 | | |
6 | | - | |
| 10 | + | |
7 | 11 | | |
8 | 12 | | |
9 | 13 | | |
10 | 14 | | |
11 | | - | |
| 15 | + | |
12 | 16 | | |
13 | 17 | | |
14 | 18 | | |
15 | 19 | | |
16 | | - | |
| 20 | + | |
17 | 21 | | |
18 | 22 | | |
19 | 23 | | |
20 | 24 | | |
21 | | - | |
| 25 | + | |
22 | 26 | | |
23 | 27 | | |
24 | 28 | | |
25 | 29 | | |
26 | | - | |
| 30 | + | |
27 | 31 | | |
28 | 32 | | |
29 | 33 | | |
30 | 34 | | |
31 | | - | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
32 | 39 | | |
33 | 40 | | |
34 | 41 | | |
35 | 42 | | |
36 | | - | |
| 43 | + | |
37 | 44 | | |
38 | 45 | | |
39 | 46 | | |
40 | 47 | | |
41 | | - | |
| 48 | + | |
42 | 49 | | |
43 | 50 | | |
44 | 51 | | |
| |||
47 | 54 | | |
48 | 55 | | |
49 | 56 | | |
50 | | - | |
| 57 | + | |
51 | 58 | | |
52 | 59 | | |
53 | 60 | | |
| |||
67 | 74 | | |
68 | 75 | | |
69 | 76 | | |
70 | | - | |
| 77 | + | |
| 78 | + | |
71 | 79 | | |
72 | 80 | | |
73 | 81 | | |
| |||
Lines changed: 11 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
10 | 15 | | |
11 | 16 | | |
12 | 17 | | |
| |||
Lines changed: 10 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
87 | | - | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
Lines changed: 33 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
593 | 593 | | |
594 | 594 | | |
595 | 595 | | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
596 | 608 | | |
597 | | - | |
598 | | - | |
599 | | - | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
600 | 621 | | |
601 | | - | |
| 622 | + | |
602 | 623 | | |
603 | 624 | | |
604 | 625 | | |
| |||
1383 | 1404 | | |
1384 | 1405 | | |
1385 | 1406 | | |
1386 | | - | |
| 1407 | + | |
1387 | 1408 | | |
1388 | 1409 | | |
1389 | 1410 | | |
| |||
1739 | 1760 | | |
1740 | 1761 | | |
1741 | 1762 | | |
1742 | | - | |
| 1763 | + | |
1743 | 1764 | | |
1744 | 1765 | | |
1745 | 1766 | | |
| |||
1816 | 1837 | | |
1817 | 1838 | | |
1818 | 1839 | | |
1819 | | - | |
| 1840 | + | |
| 1841 | + | |
| 1842 | + | |
1820 | 1843 | | |
1821 | 1844 | | |
1822 | 1845 | | |
| |||
1841 | 1864 | | |
1842 | 1865 | | |
1843 | 1866 | | |
1844 | | - | |
| 1867 | + | |
| 1868 | + | |
| 1869 | + | |
1845 | 1870 | | |
1846 | 1871 | | |
1847 | 1872 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1046 | 1046 | | |
1047 | 1047 | | |
1048 | 1048 | | |
1049 | | - | |
| 1049 | + | |
1050 | 1050 | | |
1051 | 1051 | | |
1052 | 1052 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
| 5 | + | |
| 6 | + | |
0 commit comments