Skip to content

fix(workflow): prevent panic on invalid object schema type during canvas conversion#2652

Open
phpoh wants to merge 1 commit intocoze-dev:mainfrom
phpoh:fix-schema-type-assertion-panic
Open

fix(workflow): prevent panic on invalid object schema type during canvas conversion#2652
phpoh wants to merge 1 commit intocoze-dev:mainfrom
phpoh:fix-schema-type-assertion-panic

Conversation

@phpoh
Copy link
Copy Markdown

@phpoh phpoh commented Apr 7, 2026

Summary

This PR fixes issue #2622 where workflow panics when object schema is a map[string]any instead of the expected []any slice during canvas type conversion.

Problem

The code in type_convert.go uses direct type assertions like v.Schema.([]any) in multiple places. When the schema is not a slice (e.g., a map), this causes a panic instead of returning a proper error.

Solution

Replace all direct type assertions with safe type checks using the comma-ok idiom:

// Before (panics on invalid type)
for _, subVAny := range v.Schema.([]any) {

// After (returns error on invalid type)
schemaList, ok := v.Schema.([]any)
if !ok {
    return nil, fmt.Errorf("object schema must be []any, got %T", v.Schema)
}
for _, subVAny := range schemaList {

Affected Functions

  • CanvasVariableToTypeInfo
  • CanvasBlockInputToTypeInfo
  • BlockInputToNamedTypeInfo
  • VariableToNamedTypeInfo

Testing

Added comprehensive unit tests covering:

  • Valid []any schema (should succeed)
  • Invalid map[string]any schema (should return error, not panic)
  • nil schema (should succeed)
  • Other invalid types (should return error)

All tests pass.

Test plan

  • Run unit tests: go test ./domain/workflow/internal/canvas/convert/... -v
  • Build verification: go build ./domain/workflow/...
  • Test cases cover both valid and invalid schema types

🤖 Generated with Claude Code

…vas conversion

This fix addresses issue coze-dev#2622 where workflow panics when object schema
is a map instead of expected []any slice during canvas type conversion.

Changes:
- Replace direct type assertions `v.Schema.([]any)` with safe type checks
- Add proper error messages when schema type is invalid
- Add comprehensive unit tests to verify the fix

The affected functions:
- CanvasVariableToTypeInfo
- CanvasBlockInputToTypeInfo
- BlockInputToNamedTypeInfo
- VariableToNamedTypeInfo

Before this fix, invalid schema types caused panic. After this fix,
they return clear error messages instead.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 7, 2026

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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