phrase / phrase-cli

CLI for the Phrase API
https://developers.phrase.com
MIT License
42 stars 6 forks source link

phrase pull – panic: runtime error: invalid memory address or nil pointer dereference #76

Closed t-unit closed 3 years ago

t-unit commented 3 years ago

We are having a fairly complex setup for a Flutter application. When trying to pull translations for ./ios/Runner/<locale_code>.lproj/InfoPlist.strings we run into the following error. Pushing works fine, also pulling when commenting out the file in question.

phrase pull
Downloaded de to android/app/src/main/res/values-de/strings.xml
Downloaded en to android/app/src/main/res/values/strings.xml
Downloaded de to android/app/src/main/res/values-de/strings.xml
Downloaded en to android/app/src/main/res/values/strings.xml
Downloaded de to assets/strings/intl_de.arb
Downloaded en to assets/strings/intl_en.arb
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x14d1197]

goroutine 1 [running]:
os.(*File).Name(...)
    /usr/local/go/src/os/file.go:55
github.com/phrase/phrase-cli/cmd/internal.(*Target).DownloadAndWriteToFile(0xc0002ba960, 0xc000127540, 0xc0004be000, 0x0, 0x0, 0x0, 0x2)
    /go/src/github.com/phrase/phrase-cli/cmd/internal/pull.go:179 +0x2d7
github.com/phrase/phrase-cli/cmd/internal.(*Target).Pull(0xc0002ba960, 0xc000127540, 0x0, 0x0, 0x0, 0x0)
    /go/src/github.com/phrase/phrase-cli/cmd/internal/pull.go:121 +0x19d
github.com/phrase/phrase-cli/cmd/internal.(*PullCommand).Run(0xc00016dcb8, 0xc000290000, 0x15, 0x0)
    /go/src/github.com/phrase/phrase-cli/cmd/internal/pull.go:72 +0x48f
github.com/phrase/phrase-cli/cmd.initPull.func1(0xc00027e2c0, 0x1a4d680, 0x0, 0x0)
    /go/src/github.com/phrase/phrase-cli/cmd/pull.go:24 +0xef
github.com/spf13/cobra.(*Command).execute(0xc00027e2c0, 0x1a4d680, 0x0, 0x0, 0xc00027e2c0, 0x1a4d680)
    /go/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:846 +0x2c2
github.com/spf13/cobra.(*Command).ExecuteC(0x1a14960, 0x101a501, 0x0, 0x0)
    /go/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:950 +0x375
github.com/spf13/cobra.(*Command).Execute(...)
    /go/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:887
github.com/phrase/phrase-cli/cmd.Execute()
    /go/src/github.com/phrase/phrase-cli/cmd/root.go:64 +0x2d
main.main()
    /go/src/github.com/phrase/phrase-cli/main.go:8 +0x25

our .phrase.yml

phrase:
  access_token: [...]
  project_id: [...]
  push:
    sources:
    - file: ./android/app/src/main/res/values/strings.xml
      params: 
        file_format: xml
        locale_id: 15b158324c59c8e41f25291f0db1f9d9
        tags: push
        update_translations: false
    - file: ./assets/strings/intl_en.arb
      params:
        update_translations: false
        locale_id: en
        file_format: arb
    - file: ./ios/Runner/en.lproj/Localizable.strings
      params:
        tags: push
        update_translations: false
        locale_id: en
        file_format: strings
    - file: ./ios/Runner/en.lproj/InfoPlist.strings
      params:
        tags: plist
        update_translations: false
        locale_id: en
        file_format: strings
  pull:
    targets:
    - file: ./android/app/src/main/res/values-de/strings.xml
      params:
        file_format: xml
        locale_id: b66a782309189fa5de792a030917c718
        tags: push
        format_options:
          convert_placeholder: true
    - file: ./android/app/src/main/res/values/strings.xml
      params:
        file_format: xml
        locale_id: 15b158324c59c8e41f25291f0db1f9d9
        tags: push
        format_options:
          convert_placeholder: true
    - file: ./android/app/src/main/res/values-de/strings.xml
      params:
        file_format: xml
        locale_id: b66a782309189fa5de792a030917c718
        tags: push
        format_options:
          convert_placeholder: true
    - file: ./android/app/src/main/res/values/strings.xml
      params:
        file_format: xml
        locale_id: 15b158324c59c8e41f25291f0db1f9d9
        tags: push
        format_options:
          convert_placeholder: true
    - file: ./assets/strings/intl_<locale_name>.arb
      params:
        file_format: arb
        format_options:
          convert_placeholder: true
    - file: ./ios/Runner/<locale_code>.lproj/InfoPlist.strings
      params:
        tags: plist
        file_format: strings
        format_options:
          convert_placeholder: true
    - file: ./ios/Runner/<locale_code>.lproj/Localizable.strings
      params:
        tags: push
        file_format: strings
        format_options:
          convert_placeholder: true

Used version:

% phrase info
Phrase client version:            2.1.3
Phrase client revision:           9fa1e035ee0ec440c31d4d5d4d50528a26a031c7
Phrase library revision:          v2.0.0/go.mod
Last change at:                   Thu Feb 25 13:37:56 2021 +0000
Go version:                       go1.16
t-unit commented 3 years ago

Quick update: only happens when there are no translations available with a given tag. So after adding translations for keys in the InfoPlist file, the pull went through

sbruhns commented 3 years ago

Thanks for reporting. We tracked this internally and I keep you updated as soon as we have any new information.

jonasvogel commented 3 years ago

Having the same issue too with phrase 2.1.5. Reverting back to phrase 2.0.28 worked out for me.

agarmash commented 3 years ago

The same issue on 2.1.5, before updating everything worked fine on 2.1.2.
Here's the log:

phrase pull
Downloaded de to Project/de.lproj/Localizable.strings
Downloaded el to Project/el.lproj/Localizable.strings
Downloaded en to Project/en.lproj/Localizable.strings
Downloaded es to Project/es.lproj/Localizable.strings
Downloaded fr to Project/fr.lproj/Localizable.strings
Downloaded it to Project/it.lproj/Localizable.strings
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x14d13d7]

goroutine 1 [running]:
os.(*File).Name(...)
    /usr/local/go/src/os/file.go:55
github.com/phrase/phrase-cli/cmd/internal.(*Target).DownloadAndWriteToFile(0xc000229620, 0xc00011f540, 0xc000282bd0, 0x0, 0x0, 0xc00050b9f8, 0x2)
    /go/src/github.com/phrase/phrase-cli/cmd/internal/pull.go:179 +0x2d7
github.com/phrase/phrase-cli/cmd/internal.(*Target).Pull(0xc000229620, 0xc00011f540, 0x0, 0x0, 0x1, 0xc000284e40)
    /go/src/github.com/phrase/phrase-cli/cmd/internal/pull.go:121 +0x19d
github.com/phrase/phrase-cli/cmd/internal.(*PullCommand).Run(0xc00050bcb8, 0xc000255e10, 0x15, 0x0)
    /go/src/github.com/phrase/phrase-cli/cmd/internal/pull.go:72 +0x48f
github.com/phrase/phrase-cli/cmd.initPull.func1(0xc0002782c0, 0x1a4e680, 0x0, 0x0)
    /go/src/github.com/phrase/phrase-cli/cmd/pull.go:24 +0xef
github.com/spf13/cobra.(*Command).execute(0xc0002782c0, 0x1a4e680, 0x0, 0x0, 0xc0002782c0, 0x1a4e680)
    /go/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:846 +0x2c2
github.com/spf13/cobra.(*Command).ExecuteC(0x1a15960, 0x101a501, 0x0, 0x0)
    /go/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:950 +0x375
github.com/spf13/cobra.(*Command).Execute(...)
    /go/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:887
github.com/phrase/phrase-cli/cmd.Execute()
    /go/src/github.com/phrase/phrase-cli/cmd/root.go:64 +0x2d
main.main()
    /go/src/github.com/phrase/phrase-cli/main.go:8 +0x25
tobstarr commented 3 years ago

The issue is identified and hopefully we can release a version with a fix later this week.

agarmash commented 3 years ago

2.1.6 seems to be working flawlessly, thanks for the fix!

theSoenke commented 3 years ago

@agarmash Thanks for confirming!