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

panic: runtime error: invalid memory address or nil pointer dereference [recovered] #17

Closed
aanm opened this issue Oct 16, 2015 · 4 comments

Comments

@aanm
Copy link

aanm commented Oct 16, 2015

I'm getting an error

panic: runtime error: invalid memory address or nil pointer dereference [recovered]
        panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0xa0 pc=0x535086]

goroutine 24 [running]:
testing.tRunner.func1(0xc82012e510)
        /usr/local/go/src/testing/testing.go:450 +0x171
github.com/imdario/mergo.deepMerge(0x8057e0, 0xc82014f5c0, 0x15, 0x8057e0, 0xc82014f050, 0x15, 0xc820051b28, 0x2, 0x1, 0x0, ...)
        github.com/imdario/mergo/merge.go:49 +0x836
github.com/imdario/mergo.deepMerge(0x802ea0, 0xc820168e10, 0x54, 0x802ea0, 0xc820168e00, 0x54, 0xc8200b3b18, 0x1, 0x1, 0x0, ...)
        github.com/imdario/mergo/merge.go:73 +0x556
github.com/imdario/mergo.deepMerge(0x8057e0, 0xc8200e93f0, 0xd5, 0x8057e0, 0xc82014f170, 0x15, 0xc8200b3b18, 0x0, 0xc82014f101, 0x0, ...)
        github.com/imdario/mergo/merge.go:53 +0x8c9
github.com/imdario/mergo.merge(0x7e6040, 0xc8200e93f0, 0x8057e0, 0xc82014f170, 0xc820134d01, 0x0, 0x0)
        github.com/imdario/mergo/merge.go:109 +0x2cd
github.com/imdario/mergo.MergeWithOverwrite(0x7e6040, 0xc8200e93f0, 0x8057e0, 0xc82014f170, 0x0, 0x0)
        github.com/imdario/mergo/merge.go:95 +0x50
@aanm aanm changed the title Error: reflect: call of reflect.Value.Elem on struct Value panic: runtime error: invalid memory address or nil pointer dereference [recovered] Oct 16, 2015
@darccio
Copy link
Owner

darccio commented Oct 18, 2015

Please, can you provide an example showing how are you calling MergeWithOverwrite and what kind of parameters?

@aanm
Copy link
Author

aanm commented Oct 20, 2015

@imdario Sorry for the delay, my example was more complex so I had to create a simple one.
I also tried with MapWithOverwrite and got the same output, what is the difference between MapWithOverwrite and MergeWithOverwrite?

package test

import (
    "encoding/json"
    "testing"

    "github.com/imdario/mergo"
)

var (
    request    = `{"timestamp":null, "name": "foo"}`
    maprequest = map[string]interface{}{
        "timestamp": nil,
        "name":      "foo",
        "newStuff":  "foo",
    }
)

func TestMergeWithOverwrite(t *testing.T) {
    var something map[string]interface{}
    if err := json.Unmarshal([]byte(request), &something); err != nil {
        t.Errorf("Error while Unmarshalling maprequest %s", err)
    }
    if err := mergo.MergeWithOverwrite(&something, maprequest); err != nil {
        t.Errorf("Error while merging %s", err)
    }
}

@darccio
Copy link
Owner

darccio commented Oct 24, 2015

Ok, working on it. I add it as an unit test and I'm checking it.

@darccio
Copy link
Owner

darccio commented Oct 24, 2015

Done. There was missing an "if" to check if the value from src was nil. I should check if there is another corner case like this in other points of the code.

@darccio darccio closed this as completed Oct 24, 2015
darccio added a commit that referenced this issue Oct 24, 2015
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

No branches or pull requests

2 participants