analyze_errors.ps1 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # Analyze 404 and 500 errors by module
  2. $content = Get-Content "d:\ylrz\saasadminui\api_test_results.txt" -Raw
  3. # Parse sections
  4. $sections = $content -split "=== "
  5. $notFound = @()
  6. $serverErr = @()
  7. $current = $null
  8. foreach ($section in $sections) {
  9. if ($section.StartsWith("404 Not Found")) {
  10. $lines = $section -split "`n" | Where-Object { $_.Trim() -ne "" -and $_ -notmatch "^404 Not Found" }
  11. $notFound = $lines
  12. } elseif ($section.StartsWith("500 Server Error")) {
  13. $lines = $section -split "`n" | Where-Object { $_.Trim() -ne "" -and $_ -notmatch "^500 Server Error" }
  14. $serverErr = $lines
  15. }
  16. }
  17. # Count 404 by module
  18. Write-Host "=== 404 by Module ==="
  19. $notFoundByModule = @{}
  20. foreach ($line in $notFound) {
  21. if ($line -match "^\s*/([^/]+)/") {
  22. $mod = $Matches[1]
  23. if (-not $notFoundByModule.ContainsKey($mod)) { $notFoundByModule[$mod] = 0 }
  24. $notFoundByModule[$mod]++
  25. }
  26. }
  27. $notFoundByModule.GetEnumerator() | Sort-Object Value -Descending | ForEach-Object { Write-Host " $($_.Key): $($_.Value)" }
  28. # Count 500 by module
  29. Write-Host "`n=== 500 by Module ==="
  30. $serverErrByModule = @{}
  31. foreach ($line in $serverErr) {
  32. if ($line -match "^\s*/([^/]+)/") {
  33. $mod = $Matches[1]
  34. if (-not $serverErrByModule.ContainsKey($mod)) { $serverErrByModule[$mod] = 0 }
  35. $serverErrByModule[$mod]++
  36. }
  37. }
  38. $serverErrByModule.GetEnumerator() | Sort-Object Value -Descending | ForEach-Object { Write-Host " $($_.Key): $($_.Value)" }
  39. # Now check which 404 paths map to actual controller request mappings
  40. # Look for patterns: paths with trailing /, paths with variables
  41. Write-Host "`n=== 404 Path Pattern Analysis ==="
  42. $trailingSlash = 0
  43. $variablePath = 0
  44. $normalPath = 0
  45. foreach ($line in $notFound) {
  46. if ($line -match "//") { $trailingSlash++ }
  47. elseif ($line -match "/\d+") { $variablePath++ }
  48. else { $normalPath++ }
  49. }
  50. Write-Host " Path with double slash: $trailingSlash"
  51. Write-Host " Path with numeric ID: $variablePath"
  52. Write-Host " Normal path: $normalPath"
  53. # Check if 404 paths with trailing / also fail without /
  54. Write-Host "`n=== Sample 404 paths (first 30) ==="
  55. $notFound | Select-Object -First 30 | ForEach-Object { Write-Host " $_" }
  56. # Check if 500 paths are consistent (same base path always 500)
  57. Write-Host "`n=== Sample 500 paths (first 30) ==="
  58. $serverErr | Select-Object -First 30 | ForEach-Object { Write-Host " $_" }