Skip to content

Handle transient local dev startup errors (fixes #155)#156

Open
diadal wants to merge 4 commits intocloudflare:mainfrom
diadal:fix-155-transient-startup-errors
Open

Handle transient local dev startup errors (fixes #155)#156
diadal wants to merge 4 commits intocloudflare:mainfrom
diadal:fix-155-transient-startup-errors

Conversation

@diadal
Copy link

@diadal diadal commented Feb 23, 2026

This pull request improves error handling and resilience during container startup and monitoring in the Container class. 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:

  • Added new error constants (MONITOR_FAILED_TO_FIND_CONTAINER_ERROR, CONTAINER_PORT_NOT_FOUND_ERROR, CONNECTION_REFUSED_ERROR) to identify transient container startup issues.
  • Introduced the isTransientContainerStartupError function to detect these transient errors and updated error handling logic in fetch, handleError, and monitoring code to treat them as recoverable, avoiding crashes and improving resilience. [1] [2] [3] [4] [5]

Code cleanup and refactoring:

  • Changed variable declarations from let to const for retry counters in container instance and port polling logic, improving clarity and immutability. [1] [2]
  • Minor refactor to use const instead of let in requestAndPortFromContainerFetchArgs handling.

Type and import adjustments:

  • Updated imports and type ordering for improved clarity and consistency in src/lib/container.ts.

Copilot AI review requested due to automatic review settings February 23, 2026 17:22
@diadal diadal requested a review from a team as a code owner February 23, 2026 17:22
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 an isTransientContainerStartupError helper function to identify recoverable startup errors
  • Updated error handling in containerFetch, handleError, and setupMonitorCallbacks to treat transient errors as non-fatal, returning early instead of crashing
  • Improved code quality by changing variable declarations from let to const for immutable values and alphabetically sorting type imports

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1032 to 1036
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;
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants