Back to all reviewers

validate before processing

microsoft/markitdown
Based on 2 comments
Python

Always validate input state and types before performing operations to prevent runtime errors and unexpected behavior. This includes checking data types before applying type-specific operations and preserving object state when performing validation checks.

Null Handling Python

Reviewer Prompt

Always validate input state and types before performing operations to prevent runtime errors and unexpected behavior. This includes checking data types before applying type-specific operations and preserving object state when performing validation checks.

When working with streams, restore the original position after reading during validation to avoid side effects:

# Good: Preserve stream position
cur_pos = file_stream.tell()
data = file_stream.read()
file_stream.seek(cur_pos)

When processing data, validate the type before applying operations:

# Good: Check type before text operations
if isinstance(content, str):
    content = self._strip_leading_blanks(content)

This defensive approach prevents errors from assumptions about input state or type, similar to how null checks prevent null reference exceptions.

2
Comments Analyzed
Python
Primary Language
Null Handling
Category

Source Discussions