Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove custom exit codes from Buildpack::on_error #415

Merged
merged 1 commit into from
Jun 20, 2022

Conversation

Malax
Copy link
Member

@Malax Malax commented Jun 20, 2022

Remove support for custom exit codes from Buildpack::on_error. Exit codes are part of the CNB spec and there are cases where some exit codes have special meaning to the CNB lifecycle. This put the burden on the buildpack author to not pick exit codes with special meanings, dependent on the currently executing phase. This makes Buildpack::on_error more consistent with the rest of the framework where we don't expose the interface between the buildpack and the CNB lifecycle directly but use abstractions for easier forward-compatibility and to prevent accidental misuse.

We actually made the mistake ourselves (#286) and had the default Buildpack::on_error implementation return 100 which means "failed detect" during detect instead of properly signalling an error.

Fixes #286

Copy link
Member

@edmorley edmorley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

I also wonder if at some point we should make libcnb_runtime_detect and libcnb_runtime_build stop returning exit codes of their own?

For the build case, it only ever returns 0, which seems better modelled by Result<(), ...>.

And for the detect case, it only ever returns 0 or 100 which seems better modelled by something like Result<DetectResult, ...> where DetectResult (or whatever it's called) is an enum with only two states?

Although that does mean that libcnb_runtime does end up having some CNB business logic in there (the mapping of those two detect enum variants), so maybe that's an argument against?

It just feels a bit bleugh to be returning i32s from libcnb_runtime_detect and libcnb_runtime_build.

@Malax
Copy link
Member Author

Malax commented Jun 20, 2022

I also wonder if at some point we should make libcnb_runtime_detect and libcnb_runtime_build stop returning exit codes of their own?

I have a new branch ready that at least removes all magic values for exit codes in the codebase. I'm not heavily opposed to the i32 values in those two functions since they're internal and just there to break up the code in libcnb_runtime. I think it becomes much better and (IMHO) good enough with constants.

EDIT: I just realised that both functions are no longer internal. They're pub, that might change things. I'll link the PR here as soon as it is ready. Ready now: #416

@Malax Malax merged commit 2ddfa94 into main Jun 20, 2022
@Malax Malax deleted the malax/remove-custom-exit-code branch June 20, 2022 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Default on_error exit code for internal errors is incorrect
2 participants