fix: unhelpful "cannot overwrite model once compiled" errors swallowing actual error #11057
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If an error is thrown during the payload init process, it gets ignored and an unhelpful, meaningless
⨯ OverwriteModelError: Cannot overwrite ___ model once compiled.
error is thrown instead. The actual error that caused this will never be logged. This PR fixes this and ensures the actual error is logged.
Why did this happen?
If an error is thrown during the init process, it is caught and handled by the
src/utilities/routeError.ts
- this helper properly logs the error using pino.The problem is that pino did not exist, as payload did not finish initializing - it errored during it. So, it tries to initialize payload again before logging the error... which will fail again. If payload failed initializing the first time, it will fail the second time. => No error is logged.
This PR ensures the error is logged using
console.error()
if the originating error was thrown during the payload init process, instead of attempting to initialize it again and again