Skip to content

goi18n merge resulted in "invalid memory address or nil pointer dereference" #235

@nuoyan

Description

@nuoyan

On Mac. Installed goi18n command following the README.
go version go1.14.6 darwin/amd64

Steps to reproduce:

  1. follow the steps in README to extract messages, translate, and load new langauge's file into bundle. Verify the new language worked. I could reproduce this using the code from the example for this exercise.

  2. Add a new message. In my case, I added:

	newMsg := localizer.MustLocalize(&i18n.LocalizeConfig{
		DefaultMessage: &i18n.Message{
			ID:          "NewMsg",
			Description: "A new message",
			One:         "This is a new message",
		},
		PluralCount: 0,
	})
  1. Follow Translating new messages.

After go extract, I verified the EN message file had the new message. At this moment, my EN and ES message files look like the following:

active.en.toml:

HelloPerson = "Hello {{.Name}}"

[MyUnreadEmails]
description = "The number of unread emails I have"
one = "I have {{.PluralCount}} unread email."
other = "I have {{.PluralCount}} unread emails."

[PersonUnreadEmails]
description = "The number of unread emails a person has"
one = "{{.Name}} has {{.UnreadEmailCount}} unread email."
other = "{{.Name}} has {{.UnreadEmailCount}} unread emails."

[NewMsg]
description = "A new message"
one = "This is a new message"

active.es.toml:

[HelloPerson]
hash = "sha1-5b49bfdad81fedaeefb224b0ffc2acc58b09cff5"
other = "Hola {{.Name}}"

[MyUnreadEmails]
description = "The number of unread emails I have"
hash = "sha1-6a65d17f53981a3657db1897630e9cb069053ea8"
one = "Tengo {{.PluralCount}} correo electrónico sin leer"
other = "Tengo {{.PluralCount}} correos electrónicos no leídos"

[PersonUnreadEmails]
description = "The number of unread emails a person has"
hash = "sha1-3a672fa89c5c8564bb233c907638004983792464"
one = "{{.Name}} tiene {{.UnreadEmailCount}} correo electrónico no leído"
other = "{{.Name}} tiene {{.UnreadEmailCount}} correos electrónicos no leídos"

Now run goi18n merge active.*.toml.

Got:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x11e250d]

goroutine 1 [running]:
main.hash(0xc00008ea00, 0xc000090750, 0xc0000f018c)
	/Users/foo/go/src/github.com/kouzoh/go-i18n/v2/goi18n/merge_command.go:297 +0x12d
main.merge(0xc0000ddc98, 0x860086, 0x0, 0x0, 0x124e954, 0x1, 0x124ef7c, 0x4, 0x203000, 0x203000, ...)
	/Users/foo/go/src/github.com/kouzoh/go-i18n/v2/goi18n/merge_command.go:139 +0x602
main.(*mergeCommand).execute(0xc0000b81e0, 0xc0000b2060, 0x2)
	/Users/foo/go/src/github.com/kouzoh/go-i18n/v2/goi18n/merge_command.go:92 +0x234
main.testableMain(0xc0000b2050, 0x3, 0x3, 0xc00008c058)
	/Users/foo/go/src/github.com/kouzoh/go-i18n/v2/goi18n/main.go:123 +0x3e2
main.main()
	/Users/foo/go/src/github.com/kouzoh/go-i18n/v2/goi18n/main.go:96 +0x64

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions