Skip to content

Conversation

@xdustinface
Copy link
Collaborator

@xdustinface xdustinface commented Dec 28, 2025

Add encoding='utf-8' to all file open operations in the FFI documentation generation scripts since the default Windows encoding doesnt seem to go well with it and lets the relevant pre-commit step fail for Windows in #253.

Also improved error visibility in verify_ffi.py by capturing stderr when the subprocess fails.

Summary by CodeRabbit

  • Bug Fixes
    • Improved error reporting to capture and display failure messages during documentation generation processes.
    • Ensured proper UTF-8 text encoding to guarantee consistent character handling across all platforms.

✏️ Tip: You can customize this high-level summary in your review settings.

Add `encoding='utf-8'` to all file open operations in the FFI documentation generation scripts
since the default Windows encoding doesnt seem to go well with it and lets the relevant `pre-commit` step fail for Windows in #253.

Also improved error visibility in `verify_ffi.py` by capturing stderr
when the subprocess fails.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 28, 2025

📝 Walkthrough

Walkthrough

Three Python scripts updated: one to capture stderr instead of stdout on subprocess failures for improved error reporting, and two to explicitly specify UTF-8 encoding for file I/O operations in documentation generation scripts.

Changes

Cohort / File(s) Summary
Error Handling
contrib/verify_ffi.py
Modified generate_ffi_docs() to return stderr from subprocess when exit code is non-zero; previously always returned stdout regardless of failure status
UTF-8 Encoding Specification
dash-spv-ffi/scripts/generate_ffi_docs.py, key-wallet-ffi/scripts/generate_ffi_docs.py
Added explicit encoding='utf-8' parameter to file open operations in extract_ffi_functions() (reading) and main() (writing) to ensure consistent Unicode handling across platforms

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 Stderr now whispers what stdout won't tell,
UTF-8 encoded in every shell,
No more encoding guesses in the dark,
Error messages shine—a helpful spark!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding explicit UTF-8 encoding for FFI documentation generation scripts, which aligns with the primary objectives of the PR.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/ffi-utf8

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3884314 and fdfe8ce.

📒 Files selected for processing (3)
  • contrib/verify_ffi.py
  • dash-spv-ffi/scripts/generate_ffi_docs.py
  • key-wallet-ffi/scripts/generate_ffi_docs.py
🧰 Additional context used
🧠 Learnings (7)
📓 Common learnings
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: dash-spv-ffi/CLAUDE.md:0-0
Timestamp: 2025-12-01T07:59:58.608Z
Learning: Applies to dash-spv-ffi/src/**/*.rs : Input strings in FFI functions are `*const c_char` (borrowed, not freed by C caller)
📚 Learning: 2025-12-01T07:59:58.608Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: dash-spv-ffi/CLAUDE.md:0-0
Timestamp: 2025-12-01T07:59:58.608Z
Learning: Applies to dash-spv-ffi/src/**/*.rs : Input strings in FFI functions are `*const c_char` (borrowed, not freed by C caller)

Applied to files:

  • dash-spv-ffi/scripts/generate_ffi_docs.py
📚 Learning: 2025-12-01T07:59:58.608Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: dash-spv-ffi/CLAUDE.md:0-0
Timestamp: 2025-12-01T07:59:58.608Z
Learning: Applies to dash-spv-ffi/src/**/*.rs : Add cbindgen annotations for complex types in FFI functions

Applied to files:

  • dash-spv-ffi/scripts/generate_ffi_docs.py
📚 Learning: 2025-12-01T07:59:58.608Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: dash-spv-ffi/CLAUDE.md:0-0
Timestamp: 2025-12-01T07:59:58.608Z
Learning: Applies to dash-spv-ffi/src/**/*.rs : Use `#[no_mangle] extern "C"` attribute when implementing new FFI functions in Rust

Applied to files:

  • dash-spv-ffi/scripts/generate_ffi_docs.py
📚 Learning: 2025-12-01T07:59:58.608Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: dash-spv-ffi/CLAUDE.md:0-0
Timestamp: 2025-12-01T07:59:58.608Z
Learning: Applies to dash-spv-ffi/tests/unit/**/*.rs : Add corresponding unit tests in `tests/unit/` for each new FFI function

Applied to files:

  • dash-spv-ffi/scripts/generate_ffi_docs.py
📚 Learning: 2025-12-01T07:59:58.608Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: dash-spv-ffi/CLAUDE.md:0-0
Timestamp: 2025-12-01T07:59:58.608Z
Learning: Applies to dash-spv-ffi/tests/c_tests/**/*.{c,h} : Add corresponding C tests in `tests/c_tests/` for each new FFI function

Applied to files:

  • dash-spv-ffi/scripts/generate_ffi_docs.py
📚 Learning: 2025-12-22T17:59:37.849Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-22T17:59:37.849Z
Learning: Applies to **/*-ffi/**/*.rs : Exercise careful handling at FFI boundaries for memory safety

Applied to files:

  • key-wallet-ffi/scripts/generate_ffi_docs.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
  • GitHub Check: fuzz (dash_deserialize_block)
  • GitHub Check: fuzz (dash_deserialize_witness)
  • GitHub Check: fuzz (dash_outpoint_string)
  • GitHub Check: fuzz (hashes_json)
  • GitHub Check: fuzz (hashes_sha512_256)
  • GitHub Check: fuzz (hashes_ripemd160)
  • GitHub Check: fuzz (dash_deserialize_amount)
  • GitHub Check: fuzz (hashes_sha256)
  • GitHub Check: fuzz (dash_script_bytes_to_asm_fmt)
  • GitHub Check: fuzz (hashes_cbor)
  • GitHub Check: fuzz (dash_deser_net_msg)
  • GitHub Check: fuzz (dash_deserialize_script)
  • GitHub Check: fuzz (hashes_sha512)
  • GitHub Check: fuzz (dash_deserialize_address)
  • GitHub Check: Pre-commit (ubuntu-latest)
  • GitHub Check: Pre-commit (macos-latest)
  • GitHub Check: SPV Components Tests
  • GitHub Check: RPC Tests (stable, true)
  • GitHub Check: Core Components Tests
  • GitHub Check: Key Wallet Components Tests
🔇 Additional comments (3)
key-wallet-ffi/scripts/generate_ffi_docs.py (1)

31-31: LGTM! Explicit UTF-8 encoding ensures cross-platform compatibility.

Adding encoding='utf-8' to both read and write operations prevents platform-specific encoding issues, particularly on Windows where the default is cp1252. This directly addresses the issue referenced in the PR objectives.

Also applies to: 312-312

contrib/verify_ffi.py (1)

38-41: LGTM! Improved error visibility by surfacing stderr on subprocess failures.

The logic now correctly prioritizes stderr when the subprocess exits with a non-zero code, making it easier to diagnose documentation generation failures. The fallback to stdout when stderr is empty is a reasonable default.

dash-spv-ffi/scripts/generate_ffi_docs.py (1)

32-32: LGTM! Consistent UTF-8 encoding across both FFI documentation generators.

These changes mirror the encoding fixes in key-wallet-ffi, ensuring both documentation generation scripts handle UTF-8 consistently across platforms and avoid Windows default encoding issues.

Also applies to: 373-373


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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