Handle transient local dev startup errors (fixes #155)#156
Handle transient local dev startup errors (fixes #155)#156diadal wants to merge 4 commits intocloudflare:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request enhances error handling during container startup in local development environments by introducing three new transient error types and updating error handling logic throughout the Container class. The changes aim to make the system more resilient by preventing crashes from temporary errors that occur while the container monitor is discovering instances and exposed ports.
Changes:
- Added three new error constants (
MONITOR_FAILED_TO_FIND_CONTAINER_ERROR,CONTAINER_PORT_NOT_FOUND_ERROR,CONNECTION_REFUSED_ERROR) and anisTransientContainerStartupErrorhelper function to identify recoverable startup errors - Updated error handling in
containerFetch,handleError, andsetupMonitorCallbacksto treat transient errors as non-fatal, returning early instead of crashing - Improved code quality by changing variable declarations from
lettoconstfor immutable values and alphabetically sorting type imports
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (isNoInstanceError(error) || isTransientContainerStartupError(error)) { | ||
| // Transient local-dev errors can happen before the monitor discovers the instance. | ||
| // Reset monitor so the next start attempt can re-attach. | ||
| this.monitor = undefined; | ||
| return; |
There was a problem hiding this comment.
The monitorSetup flag is not being reset when handling transient errors. This could prevent future attempts to set up monitor callbacks, as the check at line 1020 will return early if monitorSetup is still true. Consider adding this.monitorSetup = false; before line 1036 to ensure the monitor can be re-established on the next start attempt.
This pull request improves error handling and resilience during container startup and monitoring in the
Containerclass. The main focus is on identifying and gracefully handling transient errors that can occur during local development, preventing unnecessary crashes and improving the developer experience. Several error constants and utility functions have been added, and logic throughout the class has been updated to account for these transient errors.Error handling improvements:
MONITOR_FAILED_TO_FIND_CONTAINER_ERROR,CONTAINER_PORT_NOT_FOUND_ERROR,CONNECTION_REFUSED_ERROR) to identify transient container startup issues.isTransientContainerStartupErrorfunction to detect these transient errors and updated error handling logic infetch,handleError, and monitoring code to treat them as recoverable, avoiding crashes and improving resilience. [1] [2] [3] [4] [5]Code cleanup and refactoring:
lettoconstfor retry counters in container instance and port polling logic, improving clarity and immutability. [1] [2]constinstead ofletinrequestAndPortFromContainerFetchArgshandling.Type and import adjustments:
src/lib/container.ts.