Skip to content

[code-simplifier] refactor: simplify dispatch_workflow handler clarity (#20708 follow-up)#20715

Merged
pelikhan merged 1 commit intomainfrom
simplify/dispatch-workflow-clarity-45ae706c982ef8d8
Mar 12, 2026
Merged

[code-simplifier] refactor: simplify dispatch_workflow handler clarity (#20708 follow-up)#20715
pelikhan merged 1 commit intomainfrom
simplify/dispatch-workflow-clarity-45ae706c982ef8d8

Conversation

@github-actions
Copy link
Contributor

Small follow-up cleanup to the dispatch_workflow fix landed in #20708.

Files Simplified

  • actions/setup/js/dispatch_workflow.cjs — removed an unnecessary alias variable and clarified catch-block naming

Improvements Made

Removed redundant item = message alias

The handler function receives the message as message, but the code immediately created const item = message and used item for property access. This alias existed solely to avoid a name collision with a local message variable inside an inner catch block. Both the alias and the collision have been cleaned up.

Before:

const item = message;
const workflowName = item.workflow_name;
// ...
if (item.inputs && typeof item.inputs === "object") {
  for (const [key, value] of Object.entries(item.inputs)) {

After:

const workflowName = message.workflow_name;
// ...
if (message.inputs && typeof message.inputs === "object") {
  for (const [key, value] of Object.entries(message.inputs)) {

Renamed shadowing message variable to dispatchErrMessage

Inside a nested catch (dispatchError) block, a local const message = ... was declaring a variable with the same name as the outer function parameter, creating silent shadowing. Renamed to dispatchErrMessage to make the intent unambiguous.

Simplified error detail extraction with optional chaining

The previous null-guard chain was 160+ characters and hard to parse at a glance:

Before:

const message = err && typeof err === "object" && err.response && err.response.data && typeof err.response.data.message === "string" ? err.response.data.message : String(dispatchError);

After:

const dispatchErrMessage = typeof err?.response?.data?.message === "string" ? err.response.data.message : String(dispatchError);

Changes Based On

Recent changes from #20708 (dispatch_workflow honors target-repo in cross-repo relays)

Testing

  • ✅ All 22 tests pass (vitest run dispatch_workflow)
  • ✅ Linting passes (make lint-cjs)
  • ✅ No functional changes — behavior is identical

Review Focus

Please verify:

  • Functionality is preserved (same dispatch behavior)
  • No unintended variable scope issues introduced

Automated by Code Simplifier Agent — analyzing code from the last 24 hours

References: §23018774644

Generated by Code Simplifier ·

  • expires on Mar 13, 2026, 7:03 PM UTC

- Remove the redundant 'item = message' alias; use 'message' directly
- Rename the catch-block 'message' variable to 'dispatchErrMessage'
  to avoid shadowing the outer function parameter
- Simplify error detail extraction using optional chaining instead of
  a complex chain of null-guard checks

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@pelikhan pelikhan marked this pull request as ready for review March 12, 2026 22:07
Copilot AI review requested due to automatic review settings March 12, 2026 22:07
@pelikhan pelikhan merged commit e817a9a into main Mar 12, 2026
@pelikhan pelikhan deleted the simplify/dispatch-workflow-clarity-45ae706c982ef8d8 branch March 12, 2026 22:07
Copy link
Contributor

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

Follow-up refactor to the dispatch_workflow handler to improve readability and avoid variable shadowing, without changing behavior.

Changes:

  • Removed redundant item = message alias and referenced the handler parameter directly.
  • Renamed a shadowing message variable in the dispatch error path to dispatchErrMessage.
  • Simplified API error detail extraction using optional chaining.

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

You can also share your feedback on Copilot code review. Take the survey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants