Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 1, 2025

The simulator was throwing TypeErrors when users attempted to send messages after a flow had completed. This occurred due to two null pointer exceptions:

Issues Fixed

1. Cannot read properties of null (reading 'unshift') (Line 343)

When a flow completes, the server response may return runContext.events as null or undefined. The simulator was attempting to call unshift() on this null value when adding the user's message event:

// Before - would throw if runContext.events is null/undefined  
if (msgEvt) {
  runContext.events.unshift(msgEvt);
}

// After - safely handles null/undefined events
if (!runContext.events) {
  runContext.events = [];
}
if (msgEvt) {
  runContext.events.unshift(msgEvt);
}

2. Cannot read properties of undefined (reading 'status') (Line 521)

Network errors and other error scenarios could result in an error object without a response property. The error handler was accessing error.response.status without checking if response existed:

// Before - would throw if error.response is undefined
.catch(error => {
  if (error.response.status) {
    // ...
  }
  const text = error.response.status > 499 
    ? 'Server error, try again later'
    : error.response.data.error;
})

// After - safely handles missing response
.catch(error => {
  if (error.response && error.response.status) {
    // ...
  }
  const text = error.response && error.response.status > 499
    ? 'Server error, try again later'
    : error.response && error.response.data && error.response.data.error
    ? error.response.data.error
    : 'An error occurred';
})

Testing

Added comprehensive tests covering:

  • Null and undefined events arrays in updateRunContext
  • Error handling scenarios with and without response objects
  • All existing tests continue to pass (564 tests across 102 test suites)

The fixes are minimal and surgical, maintaining existing behavior while preventing runtime exceptions in edge cases.

Fixes #1332.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: rowanseymour <675558+rowanseymour@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Simulator errors when sending message after flow completes Fix simulator errors when sending message after flow completes Aug 1, 2025
@Copilot Copilot AI requested a review from rowanseymour August 1, 2025 16:41
Copilot finished work on behalf of rowanseymour August 1, 2025 16:41
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.

Simulator errors when sending message after flow completes
2 participants