From e594954bff3cc099e4a0e6a981f9b01818c9ba9d Mon Sep 17 00:00:00 2001 From: Jarred Simmer Date: Wed, 10 Feb 2021 09:02:58 -0800 Subject: [PATCH] Added length to invariant message in flib/core/hack/lib/private.php::validate_offset Summary: Improved ability to debug code when an invariant isn't met by outputting all relevant values, not just 1. Reviewed By: kmeht, viratyosin Differential Revision: D26350710 fbshipit-source-id: 548e8d4ca15eacd0cf0ade9f9bf47accaa191686 --- src/private.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/private.php b/src/private.php index 3a856b79..332d09ee 100644 --- a/src/private.php +++ b/src/private.php @@ -15,18 +15,16 @@ * offset as a positive integer. */ <<__Pure>> -function validate_offset( - int $offset, - int $length, -)[]: int { +function validate_offset(int $offset, int $length)[]: int { $original_offset = $offset; if ($offset < 0) { $offset += $length; } invariant( $offset >= 0 && $offset <= $length, - 'Offset (%d) was out-of-bounds.', + 'Offset %d was out-of-bounds for length %d', $original_offset, + $length, ); return $offset; } @@ -36,15 +34,17 @@ function validate_offset( * offset as a positive integer. */ <<__Pure>> -function validate_offset_lower_bound( - int $offset, - int $length, -)[]: int { +function validate_offset_lower_bound(int $offset, int $length)[]: int { $original_offset = $offset; if ($offset < 0) { $offset += $length; } - invariant($offset >= 0, 'Offset (%d) was out-of-bounds.', $original_offset); + invariant( + $offset >= 0, + 'Offset %d was out-of-bounds for length %d', + $original_offset, + $length, + ); return $offset; }