heroku / heroku-buildpack-python

Heroku's buildpack for Python applications.
https://www.heroku.com/python
MIT License
973 stars 1.83k forks source link

Improve detection error messages #1608

Closed edmorley closed 3 weeks ago

edmorley commented 3 weeks ago

Previously if an app was missing the necessary Python package manager files, buildpack detection would fail with the generic error message provided by the build system (see previous version of test fixtures for an example).

This error message required users to click through to the Dev Center documentation to find out what files need to be present for a Python app to work on Heroku, and there are quite a few support tickets where users have struggled to resolve this themselves (see GUS work item for ticket links).

Now a custom error message is displayed, similar to what the Node.js and PHP buildpacks do: https://github.com/heroku/heroku-buildpack-nodejs/blob/main/bin/detect https://github.com/heroku/heroku-buildpack-php/blob/main/bin/detect

This error message lists some common reasons why the files might not be found (such as them not being in the root directory), and also prints a directory listing of the root directory to help the user (and support) understand what is happening.

Lastly, the detection logic has been made more permissive, so that Python apps that are missing some of the required files (but have other misc Python related files) still pass detection, allowing us to perform the stricter file check during the build phase instead. This is particularly important for the "new app with no buildpacks set" case, where in the case of buildpack detect failure a custom detect error message is not shown by the build system (since it's not viable to show the custom message from half a dozen language buildpacks simultaneously), but a build phase error message is.

These changes also bring the classic Python buildpack more in line with the Python CNB implementation: https://github.com/heroku/buildpacks-python/blob/447c7dd978bc3069fb1baa0005a83e4720ba1e63/src/detect.rs#L4-L25 https://github.com/heroku/buildpacks-python/blob/447c7dd978bc3069fb1baa0005a83e4720ba1e63/src/errors.rs#L71-L81

GUS-W-7924407.