Skip to content

Commit

Permalink
Merge pull request #2983 from locustio/better-error-message-when-spec…
Browse files Browse the repository at this point in the history
…ifying-locustfile-via-url

When specifying locustfile fia url, output start of response text when it wasnt valid python
  • Loading branch information
cyberw authored Nov 12, 2024
2 parents 96230d9 + 7c29a29 commit a6f7780
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions locust/argument_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,17 @@ def download_locustfile_from_url(url: str) -> str:
"""
try:
response = requests.get(url)
# Check if response is valid python code
ast.parse(response.text)
except requests.exceptions.RequestException as e:
sys.stderr.write(f"Failed to get locustfile from: {url}. Exception: {e}")
sys.exit(1)
except SyntaxError:
sys.stderr.write(f"Failed to get locustfile from: {url}. Response is not valid python code.")
else:
try:
# Check if response is valid python code
ast.parse(response.text)
except SyntaxError:
sys.stderr.write(
f"Failed to get locustfile from: {url}. Response was not valid python code: '{response.text[:100]}'"
)
sys.exit(1)

with open(os.path.join(tempfile.gettempdir(), urlparse(url).path.split("/")[-1]), "w") as locustfile:
Expand Down

0 comments on commit a6f7780

Please sign in to comment.