docs: add missing errors documentation to primitives crate
What changed, and why it matters
This commit only adds missing documentation comments describing when certain functions return errors. It does not change any code logic, function signatures, or behavior. There is no security issue here.
No action needed. This is a benign documentation improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit enables the clippy::missing_errors_doc lint and adds ‘# Errors’ sections to rustdoc for three functions: Block::validate, ScriptHash::from_script, and WScriptHash::from_script. The actual implementation code is untouched. This is a documentation-only change.
Changed components
primitives/src/block.rsprimitives/src/hash_types/script_hash.rsprimitives/src/hash_types/witness_script_hash.rsprimitives/src/lib.rsInspect captured patch +17 / −1
diff --git a/primitives/src/block.rs b/primitives/src/block.rs
index 3abbb9d4..47e53e3e 100644
--- a/primitives/src/block.rs
+++ b/primitives/src/block.rs
@@ -117,6 +117,14 @@ impl Block<Unchecked> {
///
/// * The Merkle root of the header matches Merkle root of the transaction list.
/// * The witness commitment in coinbase matches the transaction list.
+ ///
+ /// # Errors
+ ///
+ /// Returns an error if:
+ /// * The block has no transactions.
+ /// * The first transaction is not a coinbase transaction.
+ /// * The Merkle root of the header does not match the Merkle root of the transaction list.
+ /// * The witness commitment in the coinbase does not match the transaction list.
pub fn validate(self) -> Result<Block<Checked>, InvalidBlockError> {
if self.transactions.is_empty() {
return Err(InvalidBlockError::NoTransactions);
diff --git a/primitives/src/hash_types/script_hash.rs b/primitives/src/hash_types/script_hash.rs
index 444c849c..a4186a44 100644
--- a/primitives/src/hash_types/script_hash.rs
+++ b/primitives/src/hash_types/script_hash.rs
@@ -32,6 +32,10 @@ impl ScriptHash {
/// > spend a P2SH output if the redemption script it refers to is >520 bytes in length.
///
/// ref: [BIP-0016](https://github.com/bitcoin/bips/blob/master/bip-0016.mediawiki#user-content-520byte_limitation_on_serialized_script_size)
+ ///
+ /// # Errors
+ ///
+ /// Returns an error if the script exceeds 520 bytes.
#[inline]
pub fn from_script<T>(redeem_script: &Script<T>) -> Result<Self, RedeemScriptSizeError>
where
diff --git a/primitives/src/hash_types/witness_script_hash.rs b/primitives/src/hash_types/witness_script_hash.rs
index 6dfb9d94..3ac39fe9 100644
--- a/primitives/src/hash_types/witness_script_hash.rs
+++ b/primitives/src/hash_types/witness_script_hash.rs
@@ -30,6 +30,10 @@ impl WScriptHash {
/// > witnessScript must match the 32-byte witness program.
///
/// ref: [BIP-0141](https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki)
+ ///
+ /// # Errors
+ ///
+ /// Returns an error if the script exceeds 10,000 bytes.
#[inline]
pub fn from_script(witness_script: &WitnessScript) -> Result<Self, WitnessScriptSizeError> {
if witness_script.len() > MAX_WITNESS_SCRIPT_SIZE {
diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs
index f550eae4..7c282316 100644
--- a/primitives/src/lib.rs
+++ b/primitives/src/lib.rs
@@ -18,7 +18,7 @@
#![warn(deprecated_in_future)]
#![doc(test(attr(warn(unused))))]
// Package-specific lint overrides.
-#![allow(clippy::missing_errors_doc)] // TODO: Write errors section in docs.
+
#[cfg(feature = "alloc")]
extern crate alloc;
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.