Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

index out of range when dump error #716

Closed
liuq19 opened this issue Dec 2, 2024 · 0 comments · Fixed by #717
Closed

index out of range when dump error #716

liuq19 opened this issue Dec 2, 2024 · 0 comments · Fixed by #717

Comments

@liuq19
Copy link
Collaborator

liuq19 commented Dec 2, 2024

panic when dump the mismatched error

output: Error: %!v(PANIC=Error method: runtime error: index out of range [30] with length 30)

package issue_test

import (
	"fmt"

	"testing"

	"github.com/bytedance/sonic"
	"github.com/stretchr/testify/assert"
)

type UnmFoo struct {
    Name string
    Age  int
}

func (p *UnmFoo) UnmarshalJSON(data []byte) error {
    var aux struct {
        Name string `json:"name"`
        Age  int    `json:"age"`
    }

    if err := sonic.Unmarshal(data, &aux); err != nil {
        return err
    }

    p.Name = aux.Name
    p.Age = aux.Age
    return nil
}

func TestIsssuexxx(t *testing.T) {
	jsonData := `{"name": "Alice", "age": "30"}`
    var obj UnmFoo
    err := sonic.Unmarshal([]byte(jsonData), &obj)
	assert.Error(t, err)
    if err != nil {
        fmt.Println("Error:", err)
    }
}
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 a pull request may close this issue.

1 participant