While working on some PRs I came across error codes all around the repository. I did try to find free error codes, yet it's so easy to mess things up by introducing duplicated errors and not keeping the docs updated with all the possible values.
As discussed in slack, one possible solution is to replace numeric error codes with string constants instead, for example:
0020 => MISSING_STORAGE_CONFIG
Also, having a single source of truth for those errors (a single php file defining them) would make it a lot easier to both keep docs updated and introducing new exceptions to the codebase.
This is no easy task though, and it would be a breaking change to the API
After reading the discussion over the Slack, I agree with @WoLfulus that we need some way to document (list) the all the error code in once place in the API codebase.
I face the issue while working on #1064 I had to throw two new exceptions, and docs on that stage showing the 0020 is the last exception code used.
I found 0021 is used in some other place but it's not documented. So I create 0022, 0023 code for my use case, and update the docs too.
But the 0022 is also used in some places. So if we have one truth of source for all the error_code this does not happen at all.
The approach mentioned by @WoLfulus sound great.
:+1: I'm in agreement, one source with a list of constants sounds like the better alternative. Especially with multiple people working on Directus, as it'll make the error code finding easier.
To achieve better clarity/visibility, we are now tracking feature requests within the Feature Request project board.
This issue being closed does not mean it's not being considered.
I've shifted this to a feature request, but please let me know if there are any parts of this that need fixing and we can open individual tickets for those bugs.
Most helpful comment
:+1: I'm in agreement, one source with a list of constants sounds like the better alternative. Especially with multiple people working on Directus, as it'll make the
error code findingeasier.