feat(compiler2): require explicit throws on function types (E0151)#4034
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (86)
📒 Files selected for processing (46)
🚧 Files skipped from review as they are similar to previous changes (44)
📝 WalkthroughWalkthroughThe PR restricts omitted function-type ChangesFunction throws typing
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant BAMLSource
participant HIRSignatureElaboration
participant TIRTypeLowering
participant DiagnosticMapping
BAMLSource->>HIRSignatureElaboration: Parse function types
HIRSignatureElaboration->>TIRTypeLowering: Preserve or infer throws clause
TIRTypeLowering->>DiagnosticMapping: Emit FunctionTypeMissingThrows
DiagnosticMapping-->>BAMLSource: Report E0151
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
⏭️ Performance benchmarks were skippedPerf benchmarks (CodSpeed) are opt-in on pull requests — they no longer run on every push. They always run automatically after merge to To run them on this PR, do any of the following, then push a commit (or re-run CI):
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@baml_language/sdks/nodejs/bridge_nodejs/typescript_src/proto/baml_cffi.js`:
- Around line 253-255: Update the generated encodeDelimited method for the
relevant message to fork the provided Writer before encoding, preserving framing
when a Writer is reused; apply the same writer-fork guard consistently across
the other generated encodeDelimited methods, or regenerate the file from the
protobufjs template.
In `@baml_language/TYPE_SYSTEM.md`:
- Line 329: Remove the duplicated E0151 rejection sentence in rule 5, keeping
one complete statement that documents the required throws clause and affected
positions.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: e2bac374-c2a8-40b0-8c6b-ced9d97fd32c
⛔ Files ignored due to path filters (82)
baml_language/crates/baml_tests/snapshots/broken_syntax/optional_parameter_defaults/baml_tests__broken_syntax__optional_parameter_defaults__01_lexer__function_type_defaults.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/broken_syntax/optional_parameter_defaults/baml_tests__broken_syntax__optional_parameter_defaults__02_parser__function_type_defaults.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/broken_syntax/optional_parameter_defaults/baml_tests__broken_syntax__optional_parameter_defaults__05_diagnostics.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/compiles/__baml_std__/baml_tests__compiles____baml_std____03_hir.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/compiles/__baml_std__/baml_tests__compiles____baml_std____04_tir.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/compiles/optional_function_parameters/baml_tests__compiles__optional_function_parameters__01_lexer__main.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/compiles/optional_function_parameters/baml_tests__compiles__optional_function_parameters__02_parser__main.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/compiles/optional_function_parameters/baml_tests__compiles__optional_function_parameters__03_hir.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/compiles/optional_function_parameters/baml_tests__compiles__optional_function_parameters__10_formatter__main.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/compiles/paren_union_test/baml_tests__compiles__paren_union_test__01_lexer__test.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/compiles/paren_union_test/baml_tests__compiles__paren_union_test__02_parser__test.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/compiles/paren_union_test/baml_tests__compiles__paren_union_test__03_hir.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/compiles/paren_union_test/baml_tests__compiles__paren_union_test__04_tir.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/compiles/paren_union_test/baml_tests__compiles__paren_union_test__10_formatter__test.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/compiles/parser_statements/baml_tests__compiles__parser_statements__01_lexer__assignments.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/compiles/parser_statements/baml_tests__compiles__parser_statements__02_parser__assignments.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/compiles/parser_statements/baml_tests__compiles__parser_statements__03_hir.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/compiles/parser_statements/baml_tests__compiles__parser_statements__10_formatter__assignments.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/compiles/patterns_new/baml_tests__compiles__patterns_new__01_lexer__patterns_new.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/compiles/patterns_new/baml_tests__compiles__patterns_new__02_parser__patterns_new.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/compiles/patterns_new/baml_tests__compiles__patterns_new__03_hir.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/compiles/patterns_new/baml_tests__compiles__patterns_new__04_5_mir.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/compiles/patterns_new/baml_tests__compiles__patterns_new__04_tir.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/compiles/patterns_new/baml_tests__compiles__patterns_new__06_codegen.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/compiles/patterns_new/baml_tests__compiles__patterns_new__10_formatter__patterns_new.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/closure_errors/baml_tests__diagnostic_errors__closure_errors__01_lexer__closure_errors.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/closure_errors/baml_tests__diagnostic_errors__closure_errors__02_parser__closure_errors.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/closure_errors/baml_tests__diagnostic_errors__closure_errors__03_hir.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/closure_errors/baml_tests__diagnostic_errors__closure_errors__04_tir.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/closure_errors/baml_tests__diagnostic_errors__closure_errors__05_diagnostics.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/closure_errors/baml_tests__diagnostic_errors__closure_errors__10_formatter__closure_errors.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/format_checks/baml_tests__diagnostic_errors__format_checks__01_lexer__class_decls.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/format_checks/baml_tests__diagnostic_errors__format_checks__01_lexer__function_decls.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/format_checks/baml_tests__diagnostic_errors__format_checks__01_lexer__type_alias_decls.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/format_checks/baml_tests__diagnostic_errors__format_checks__02_parser__class_decls.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/format_checks/baml_tests__diagnostic_errors__format_checks__02_parser__function_decls.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/format_checks/baml_tests__diagnostic_errors__format_checks__02_parser__type_alias_decls.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/format_checks/baml_tests__diagnostic_errors__format_checks__03_hir.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/format_checks/baml_tests__diagnostic_errors__format_checks__04_tir.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/format_checks/baml_tests__diagnostic_errors__format_checks__05_diagnostics.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/format_checks/baml_tests__diagnostic_errors__format_checks__10_formatter__class_decls.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/format_checks/baml_tests__diagnostic_errors__format_checks__10_formatter__function_decls.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/format_checks/baml_tests__diagnostic_errors__format_checks__10_formatter__type_alias_decls.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/function_type_missing_throws/baml_tests__diagnostic_errors__function_type_missing_throws__01_lexer__negative.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/function_type_missing_throws/baml_tests__diagnostic_errors__function_type_missing_throws__01_lexer__positive.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/function_type_missing_throws/baml_tests__diagnostic_errors__function_type_missing_throws__02_parser__negative.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/function_type_missing_throws/baml_tests__diagnostic_errors__function_type_missing_throws__02_parser__positive.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/function_type_missing_throws/baml_tests__diagnostic_errors__function_type_missing_throws__03_hir.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/function_type_missing_throws/baml_tests__diagnostic_errors__function_type_missing_throws__04_tir.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/function_type_missing_throws/baml_tests__diagnostic_errors__function_type_missing_throws__05_diagnostics.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/function_type_missing_throws/baml_tests__diagnostic_errors__function_type_missing_throws__10_formatter__negative.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/function_type_missing_throws/baml_tests__diagnostic_errors__function_type_missing_throws__10_formatter__positive.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/function_type_throws/baml_tests__diagnostic_errors__function_type_throws__01_lexer__negative.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/function_type_throws/baml_tests__diagnostic_errors__function_type_throws__02_parser__negative.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/function_type_throws/baml_tests__diagnostic_errors__function_type_throws__03_hir.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/function_type_throws/baml_tests__diagnostic_errors__function_type_throws__04_tir.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/function_type_throws/baml_tests__diagnostic_errors__function_type_throws__10_formatter__negative.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/function_types/baml_tests__diagnostic_errors__function_types__01_lexer__function_types.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/function_types/baml_tests__diagnostic_errors__function_types__02_parser__function_types.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/function_types/baml_tests__diagnostic_errors__function_types__03_hir.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/function_types/baml_tests__diagnostic_errors__function_types__04_tir.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/function_types/baml_tests__diagnostic_errors__function_types__10_formatter__function_types.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/optional_parameter_defaults/baml_tests__diagnostic_errors__optional_parameter_defaults__01_lexer__unsupported_contexts.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/optional_parameter_defaults/baml_tests__diagnostic_errors__optional_parameter_defaults__02_parser__unsupported_contexts.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/optional_parameter_defaults/baml_tests__diagnostic_errors__optional_parameter_defaults__03_hir.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/optional_parameter_defaults/baml_tests__diagnostic_errors__optional_parameter_defaults__04_tir.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/optional_parameter_defaults/baml_tests__diagnostic_errors__optional_parameter_defaults__10_formatter__unsupported_contexts.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/patterns_class_destructure/baml_tests__diagnostic_errors__patterns_class_destructure__01_lexer__patterns_class_destructure.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/patterns_class_destructure/baml_tests__diagnostic_errors__patterns_class_destructure__02_parser__patterns_class_destructure.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/patterns_class_destructure/baml_tests__diagnostic_errors__patterns_class_destructure__03_hir.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/patterns_class_destructure/baml_tests__diagnostic_errors__patterns_class_destructure__04_tir.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/patterns_class_destructure/baml_tests__diagnostic_errors__patterns_class_destructure__10_formatter__patterns_class_destructure.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/void_return_type/baml_tests__diagnostic_errors__void_return_type__01_lexer__function_type_throws.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/void_return_type/baml_tests__diagnostic_errors__void_return_type__01_lexer__void_function_type.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/void_return_type/baml_tests__diagnostic_errors__void_return_type__02_parser__function_type_throws.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/void_return_type/baml_tests__diagnostic_errors__void_return_type__02_parser__void_function_type.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/void_return_type/baml_tests__diagnostic_errors__void_return_type__03_hir.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/void_return_type/baml_tests__diagnostic_errors__void_return_type__04_tir.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/void_return_type/baml_tests__diagnostic_errors__void_return_type__05_diagnostics.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/void_return_type/baml_tests__diagnostic_errors__void_return_type__10_formatter__function_type_throws.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/diagnostic_errors/void_return_type/baml_tests__diagnostic_errors__void_return_type__10_formatter__void_function_type.snapis excluded by!**/*.snapbaml_language/sdks/nodejs/bridge_nodejs/dist/proto/baml_cffi.jsis excluded by!**/dist/**
📒 Files selected for processing (41)
baml_language/TYPE_SYSTEM.mdbaml_language/crates/baml_builtins2/baml_std/baml/ns_csv/csv.bamlbaml_language/crates/baml_builtins2/baml_std/baml/ns_llm/llm.bamlbaml_language/crates/baml_builtins2/baml_std/baml/ns_llm/llm_types.bamlbaml_language/crates/baml_compiler2_hir/src/signature.rsbaml_language/crates/baml_compiler2_tir/src/builder.rsbaml_language/crates/baml_compiler2_tir/src/infer_context.rsbaml_language/crates/baml_compiler2_tir/src/inference.rsbaml_language/crates/baml_compiler2_tir/src/lower_type_expr.rsbaml_language/crates/baml_compiler_diagnostics/src/diagnostic.rsbaml_language/crates/baml_lsp2_actions/src/check.rsbaml_language/crates/baml_tests/baml_src/ns_optional_function_parameters/optional_function_parameters.bamlbaml_language/crates/baml_tests/projects/broken_syntax/optional_parameter_defaults/function_type_defaults.bamlbaml_language/crates/baml_tests/projects/compiles/optional_function_parameters/main.bamlbaml_language/crates/baml_tests/projects/compiles/paren_union_test/test.bamlbaml_language/crates/baml_tests/projects/compiles/parser_statements/assignments.bamlbaml_language/crates/baml_tests/projects/compiles/patterns_new/patterns_new.bamlbaml_language/crates/baml_tests/projects/diagnostic_errors/closure_errors/closure_errors.bamlbaml_language/crates/baml_tests/projects/diagnostic_errors/format_checks/class_decls.bamlbaml_language/crates/baml_tests/projects/diagnostic_errors/format_checks/function_decls.bamlbaml_language/crates/baml_tests/projects/diagnostic_errors/format_checks/type_alias_decls.bamlbaml_language/crates/baml_tests/projects/diagnostic_errors/function_type_missing_throws/negative.bamlbaml_language/crates/baml_tests/projects/diagnostic_errors/function_type_missing_throws/positive.bamlbaml_language/crates/baml_tests/projects/diagnostic_errors/function_type_throws/negative.bamlbaml_language/crates/baml_tests/projects/diagnostic_errors/function_types/function_types.bamlbaml_language/crates/baml_tests/projects/diagnostic_errors/optional_parameter_defaults/unsupported_contexts.bamlbaml_language/crates/baml_tests/projects/diagnostic_errors/patterns_class_destructure/patterns_class_destructure.bamlbaml_language/crates/baml_tests/projects/diagnostic_errors/void_return_type/function_type_throws.bamlbaml_language/crates/baml_tests/projects/diagnostic_errors/void_return_type/void_function_type.bamlbaml_language/crates/baml_tests/src/compiler2_hir.rsbaml_language/crates/baml_tests/src/compiler2_tir/inference.rsbaml_language/crates/baml_tests/src/compiler2_tir/phase3a.rsbaml_language/crates/baml_tests/src/compiler2_tir/phase6.rsbaml_language/crates/baml_tests/src/compiler2_tir/phase8_exceptions.rsbaml_language/crates/baml_tests/src/engine.rsbaml_language/crates/bex_engine/tests/fn_typed_slots.rsbaml_language/crates/bex_engine/tests/host_value_callable.rsbaml_language/crates/bex_engine/tests/identity.rsbaml_language/crates/bex_engine/tests/prof_gate.rsbaml_language/sdks/nodejs/bridge_nodejs/typescript_src/proto/baml_cffi.jsbaml_language/test_simple.baml
| InboundValue.encodeDelimited = function encodeDelimited(message, writer) { | ||
| return this.encode(message, writer && writer.len ? writer.fork() : writer).ldelim(); | ||
| return this.encode(message, writer).ldelim(); | ||
| }; |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Check whether any caller reuses a single Writer across multiple encodeDelimited calls
# (the scenario that triggers the corruption), and locate the codegen source for this file.
rg -nP 'encodeDelimited\s*\(' --type=ts -g '!**/baml_cffi.js' -C3
fd -HI 'pbjs|protoc-gen|codegen' baml_language/sdks/nodejsRepository: BoundaryML/baml
Length of output: 153
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect the affected implementation and nearby generated patterns.
sed -n '240,265p' baml_language/sdks/nodejs/bridge_nodejs/typescript_src/proto/baml_cffi.js
printf '\n---\n'
sed -n '1,40p' baml_language/sdks/nodejs/bridge_nodejs/typescript_src/proto/baml_cffi.js
# Find the protobufjs version pinned in the repo.
rg -n '"protobufjs"|protobufjs' baml_language/sdks/nodejs/package.json baml_language/sdks/nodejs/package-lock.json baml_language/sdks/nodejs/yarn.lock baml_language/sdks/nodejs/pnpm-lock.yaml -SRepository: BoundaryML/baml
Length of output: 3189
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Locate the NodeJS SDK package and protobufjs pin.
fd -HI 'package.json|pnpm-lock.yaml|yarn.lock|package-lock.json' baml_language -t f
printf '\n=== package.json candidates ===\n'
for f in $(fd -HI 'package.json' baml_language -t f); do
echo "--- $f"
rg -n '"protobufjs"|protobufjs' "$f" -S || true
done
printf '\n=== likely generator/source files ===\n'
rg -n 'Source:|Proto:|pnpm build:debug|baml_cffi\.js|encodeDelimited' baml_language/crates baml_language/sdks/nodejs -S --glob '!**/baml_cffi.js'Repository: BoundaryML/baml
Length of output: 24597
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Find all encodeDelimited usages and any code that reuses a Writer instance.
rg -n "encodeDelimited\s*\(" baml_language -S
printf '\n--- Writer reuse patterns ---\n'
rg -n "new \$protobuf\.Writer|Writer\.create\(|writer\s*=\s*.*Writer|\.ldelim\(\)" baml_language/sdks/nodejs/bridge_nodejs -SRepository: BoundaryML/baml
Length of output: 50371
🌐 Web query:
protobufjs static-module encodeDelimited writer.len fork ldelim 7.6.2 template issue 1063
💡 Result:
The issue you are referencing, documented as Issue 1063 in the protobuf.js repository, pertains to an error in the generated code for encodeDelimited when using the static-module target [1]. Specifically, the generated code for encodeDelimited in earlier versions of protobuf.js used the following implementation: return this.encode(message, writer).ldelim; This implementation can cause errors during decoding (such as invalid wire type) when encoding multiple messages or when the writer state is not handled correctly, because it blindly calls ldelim without ensuring the writer has been properly forked [1]. The correct implementation, which ensures the writer is only forked when necessary, is: return this.encode(message, writer && writer.len? writer.fork: writer).ldelim; This fix was addressed in the library's codebase via a commit (related to the fix for Issue 531) that updated the TypePrototype.encodeDelimited method [2]. If you are encountering this in your project, ensure you are using a recent version of protobuf.js. If you must use an older version, you may need to patch the generated JavaScript file to include the correct writer handling logic [1][2].
Citations:
- 1: Typescript Encode/Decode delimited error with pbjs/pbts gencode protobufjs/protobuf.js#1063
- 2: protobufjs/protobuf.js@78952a5
Restore the writer fork guard in encodeDelimited.
return this.encode(message, writer).ldelim(); breaks length-delimited framing when a Writer is reused, because ldelim() then covers all accumulated bytes instead of just the current message. Keep the fork guard here and in the other generated encodeDelimited methods, or regenerate this file from the protobufjs template.
Proposed fix
-return this.encode(message, writer).ldelim();
+return this.encode(message, writer && writer.len ? writer.fork() : writer).ldelim();📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| InboundValue.encodeDelimited = function encodeDelimited(message, writer) { | |
| return this.encode(message, writer && writer.len ? writer.fork() : writer).ldelim(); | |
| return this.encode(message, writer).ldelim(); | |
| }; | |
| InboundValue.encodeDelimited = function encodeDelimited(message, writer) { | |
| return this.encode(message, writer && writer.len ? writer.fork() : writer).ldelim(); | |
| }; |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@baml_language/sdks/nodejs/bridge_nodejs/typescript_src/proto/baml_cffi.js`
around lines 253 - 255, Update the generated encodeDelimited method for the
relevant message to fork the provided Writer before encoding, preserving framing
when a Writer is reused; apply the same writer-fork guard consistently across
the other generated encodeDelimited methods, or regenerate the file from the
protobufjs template.
Binary size checks passed✅ 7 passed
Generated by |
fda0cc3 to
8ee4135
Compare
8ee4135 to
3bf563c
Compare
3bf563c to
b34e7c4
Compare
…306) Enforce TYPE_SYSTEM.md rule 5: a function type may omit its throws clause only as an immediate callback parameter of a function declaration (rule 4, opened to a synthetic effect param). Everywhere else - type aliases, class fields, let annotations, patterns, lambda parameters, nested and return positions - an omitted clause was silently defaulted to 'throws never'; it is now rejected with the new FunctionTypeMissingThrows diagnostic (E0151), recovering with 'never' so downstream checking does not cascade. Lambda parameters must be explicit because rule 4's mechanism cannot apply: a lambda is a realized value with no generic binder to open an effect parameter on. HIR signature elaboration no longer back-fills nested omissions with never (fill_omitted_nested_throws_with_never deleted) and no longer derives a return-root callback surface (elaborate_immediate_function_return_root deleted): everything that reaches TIR lowering with throws: None is by construction a rule-5 position, so lower_type_expr is the single emission point. Migrate the stdlib (ns_llm prompt closures, ns_csv on_skip callbacks, tagged-string role callback) and all test fixtures to explicit 'throws never', preserving the previously implicit semantics exactly; migrated TIR snapshots are unchanged. New diagnostic project function_type_missing_throws covers all rule-5 positions negative and positive.
b34e7c4 to
ba34db3
Compare
Closes B-306 (TYPE_SYSTEM.md rule 5).
What
A function type must declare its
throwsclause everywhere the error type cannot be inferred. Previously an omitted clause was silentlythrows neverin every position; now it is rejected with the new E0151FunctionTypeMissingThrowsdiagnostic (recovering withneverso downstream checking does not cascade).Still legal (rule 4): an immediate callback parameter of a function declaration - opened to an implicit effect generic, unchanged:
Now errors (rule 5):
Lambda parameters must be explicit because rule 4's mechanism cannot apply to them: a lambda is a realized (monomorphic) value with no generic binder to hang an implicit effect parameter on, and per spec there is no silent default.
How
lower_type_expris the single emission point: HIR signature elaboration no longer back-fills nested omissions withnever(fill_omitted_nested_throws_with_neverdeleted) and no longer derives a return-root callback surface (elaborate_immediate_function_return_rootdeleted), so anything reaching TIR withthrows: Noneis a rule-5 position by construction.return (cb: ...) -> int { wrap(cb) }); returning the bare generic value does not instantiate its effect param (pre-existing inference limitation, previously masked by the return-root derivation).Migration
Stdlib (
ns_llmprompt closures,ns_csvon_skip, tagged-stringrolecallback) and all fixtures annotated with explicitthrows never- semantically identical to the old silent default; migrated fixtures' TIR snapshots are unchanged, confirming no semantic drift. Newfunction_type_missing_throwsdiagnostic project covers every rule-5 position (including a bare lambda parameter) plus the rule-4 positives.Local runs green: baml_tests (lib + all integration binaries incl. standalone baml_test), lsp2_actions_tests, compiler2_tir/hir, bex_engine, diagnostics.
Summary by CodeRabbit
New Features
throws never) typing for callback/lambda patterns.Bug Fixes
throwsannotations across nested functions, optional calls, higher-order functions, and callback positions.throwsclause.Tests