chore(test-registry): Add more descriptive error code for common error#16790
chore(test-registry): Add more descriptive error code for common error#16790
Conversation
| const statusCode = publishImageContainerRunProcess.status; | ||
|
|
||
| if (statusCode !== 0) { | ||
| if (statusCode === 137) { | ||
| throw new Error( | ||
| `Publish Image Container failed with exit code ${statusCode}, possibly due to memory issues. Consider increasing the memory limit for the container.`, | ||
| ); | ||
| } | ||
| throw new Error(`Publish Image Container failed with exit code ${statusCode}`); |
There was a problem hiding this comment.
I like the description, it's quite nice! 🙏🏼
For the sake of give my two cents: since throw won't will prevent the rest of the code to run, perhaps we may as well avoid the embedded if statements
| const statusCode = publishImageContainerRunProcess.status; | |
| if (statusCode !== 0) { | |
| if (statusCode === 137) { | |
| throw new Error( | |
| `Publish Image Container failed with exit code ${statusCode}, possibly due to memory issues. Consider increasing the memory limit for the container.`, | |
| ); | |
| } | |
| throw new Error(`Publish Image Container failed with exit code ${statusCode}`); | |
| const statusCode = publishImageContainerRunProcess.status; | |
| if (statusCode !== 0) { | |
| throw new Error(`Publish Image Container failed with exit code ${statusCode}`); | |
| } | |
| if (statusCode === 137) { | |
| throw new Error( | |
| `Publish Image Container failed with exit code ${statusCode}, possibly due to memory issues. Consider increasing the memory limit for the container.`, | |
| ); |
It's not so much for the performance benefits (since that's for testing), but I find it easier to read, as far as I'm concerned 😁
Let me know if there is something I'm missing
There was a problem hiding this comment.
With your suggestion, it would throw already in the first condition (!== 0) when the status code is 137. It would never reach the second statement.
There was a problem hiding this comment.
My bad, sorry, you're absolutely right, I don't know what I was thinking here. Ignore me, all good 😅
| const statusCode = publishImageContainerRunProcess.status; | ||
|
|
||
| if (statusCode !== 0) { | ||
| if (statusCode === 137) { |
There was a problem hiding this comment.
l: I am never a big fan of having such nested if clauses :D Instead, what about doing something like this:
const message = statusCode === 137 ? '....' : `Publish Image Container failed with exit code ${statusCode}`;
throw new Error(message);There was a problem hiding this comment.
I'm not a fan of nested if clauses either.
I really like your approach but what if we want to handle other specific status codes later?
The error code 137 is a very common error when running E2E tests. Starting colima only with
colima startoften results in too little memory and it makes sense to add a more descriptive message here.To make it work with Colima, it's better to start it with
colima start --cpu 10 --memory 12 --network-address