forked from Stellar-Uzima/Uzima-Contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_error_codes.sh
More file actions
executable file
·47 lines (40 loc) · 1.62 KB
/
Copy pathcheck_error_codes.sh
File metadata and controls
executable file
·47 lines (40 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env bash
# Validates that all error codes in errors.rs files fall within the approved
# category ranges defined in docs/ERROR_CODES.md. Exits non-zero on any violation.
set -euo pipefail
CONTRACTS_DIR="$(cd "$(dirname "$0")/.." && pwd)/contracts"
VIOLATIONS=0
check_file() {
local file="$1"
local contract
contract=$(basename "$(dirname "$(dirname "$file")")")
while IFS= read -r line; do
# Match variant assignments: SomeName = 123,
if [[ "$line" =~ ^[[:space:]]+[A-Za-z][A-Za-z0-9_]*[[:space:]]*=[[:space:]]*([0-9]+), ]]; then
code="${BASH_REMATCH[1]}"
# Validate code falls in one of the approved ranges
if ! (( (code >= 100 && code <= 999) )); then
echo "VIOLATION in $contract ($file): code $code is outside 100-999 range"
VIOLATIONS=$((VIOLATIONS + 1))
fi
# Check for legacy sequential codes (1-99) which indicate not-yet-migrated files
if (( code >= 1 && code <= 99 )); then
echo "VIOLATION in $contract ($file): code $code uses legacy sequential numbering (expected 100+)"
VIOLATIONS=$((VIOLATIONS + 1))
fi
fi
done < "$file"
}
echo "Checking error codes across contracts..."
while IFS= read -r -d '' file; do
check_file "$file"
done < <(find "$CONTRACTS_DIR" -name "errors.rs" -print0)
if (( VIOLATIONS > 0 )); then
echo ""
echo "FAIL: $VIOLATIONS error code violation(s) found."
echo "See docs/ERROR_CODES.md for the approved ranges."
exit 1
else
echo "OK: all error codes are within approved ranges."
exit 0
fi