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

1.0.1 release results in segfault on M1 mac #283

Closed
bianchidotdev opened this issue Jun 22, 2022 · 4 comments · Fixed by #284
Closed

1.0.1 release results in segfault on M1 mac #283

bianchidotdev opened this issue Jun 22, 2022 · 4 comments · Fixed by #284

Comments

@bianchidotdev
Copy link

I tried installing lefthook on a new m1 mac and ran into segfaults on every command.

 λ  lefthook run pre-commit
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x160 pc=0x10071d2c0]

goroutine 1 [running]:
github.com/spf13/viper.(*Viper).AllKeys(0x0)
	/home/ian/go/pkg/mod/github.com/spf13/viper@v1.9.0/viper.go:1942 +0x60
github.com/spf13/viper.(*Viper).AllSettings(0x0)
	/home/ian/go/pkg/mod/github.com/spf13/viper@v1.9.0/viper.go:2023 +0x34
github.com/spf13/viper.(*Viper).Unmarshal(0x0, {0x1007ef9a0, 0x1400022a4c0}, {0x0, 0x0, 0x0})
	/home/ian/go/pkg/mod/github.com/spf13/viper@v1.9.0/viper.go:1038 +0x28
github.com/evilmartians/lefthook/internal/config.mergeCommands(0x140000f3680, 0x140000f3800)
	/home/ian/src/evil/lefthook/internal/config/command.go:75 +0x2b8
github.com/evilmartians/lefthook/internal/config.unmarshalHooks(0x140000f3680, 0x140000f3800)
	/home/ian/src/evil/lefthook/internal/config/hook.go:47 +0x40
github.com/evilmartians/lefthook/internal/config.addHook({0x10075cddb, 0xa}, 0x14000096180, 0x14000096300, 0x140000e60e0)
	/home/ian/src/evil/lefthook/internal/config/load.go:147 +0x70
github.com/evilmartians/lefthook/internal/config.unmarshalConfigs(0x14000096180, 0x14000096300, 0x140000e60e0)
	/home/ian/src/evil/lefthook/internal/config/load.go:109 +0xc4
github.com/evilmartians/lefthook/internal/config.Load({0x10086d440, 0x100aaeda8}, {0x14000136280, 0x30})
	/home/ian/src/evil/lefthook/internal/config/load.go:38 +0x108
github.com/evilmartians/lefthook/internal/lefthook.(*Lefthook).Run(0x14000092040, {0x16f9735c5, 0xa}, {0x14000111310, 0x0, 0x0})
	/home/ian/src/evil/lefthook/internal/lefthook/run.go:48 +0xe4
github.com/evilmartians/lefthook/internal/lefthook.Run(0x1400012a1f8, {0x16f9735c5, 0xa}, {0x14000111310, 0x0, 0x0})
	/home/ian/src/evil/lefthook/internal/lefthook/run.go:39 +0x80
main.newRunCmd.func1(0x140001aec80, {0x14000111310, 0x1, 0x1})
	/home/ian/src/evil/lefthook/cmd/lefthook/run.go:18 +0x70
github.com/spf13/cobra.(*Command).execute(0x140001aec80, {0x140001112f0, 0x1, 0x1})
	/home/ian/go/pkg/mod/github.com/spf13/cobra@v1.2.1/command.go:856 +0x668
github.com/spf13/cobra.(*Command).ExecuteC(0x140001ae000)
	/home/ian/go/pkg/mod/github.com/spf13/cobra@v1.2.1/command.go:974 +0x410
github.com/spf13/cobra.(*Command).Execute(...)
	/home/ian/go/pkg/mod/github.com/spf13/cobra@v1.2.1/command.go:902
main.main()
	/home/ian/src/evil/lefthook/cmd/lefthook/main.go:12 +0x24

I've installed it via brew, rubygems, go, and by directly downloading the binary for the ARM macs.

I just downgraded to 0.8.0 and that version is working just fine for me. Happy to help debug if you need additional information. Otherwise, this is out of my wheelhouse to look into myself.

@mrexox
Copy link
Member

mrexox commented Jun 23, 2022

Hi @michaeldbianchi! Thank you for reporting!

Could you provide your lefthook.yml (and lefthook-local.yml if it exists) config so that I could reproduce the bug?

@bianchidotdev
Copy link
Author

I tried paring it down as much as possible. Looks like it's due to anchors? Anyhow, I won't speculate further. I can reproduce it with this

# Refer for explanation to following link:
# https://github.com/evilmartians/lefthook/blob/master/docs/full_guide.md

reconciliation: &reconciliation
  piped: true
  1_yarn:
    tags: reconciliation
    files: git diff --name-only HEAD main
    glob: '{package.json,yarn.lock}'
    run: make install_js_packages
    tags: frontend dependencies
  2_gem:
    tags: reconciliation
    files: git diff --name-only HEAD main
    glob: '{GEMFILE,GEMFILE.lock}'
    run: make bundle
    tags: backend dependencies

post-checkout:
  commands: *reconciliation
post-merge:
  commands: *reconciliation
post-rewrite:
  commands: *reconciliation

@mrexox
Copy link
Member

mrexox commented Jun 24, 2022

I've checked it locally and I see 2 problems here:

  1. piped is in a wrong place 😅
  2. With 1.0.0 lefthook crashes if the commands structure is misused.

piped option should be specified upper than commands option. This is a global option for commands and scripts. When I removed it - everything worked just fine. This can be a workaround.

You can use this config for example. It will behave the same way:

# Refer for explanation to following link:
# https://github.com/evilmartians/lefthook/blob/master/docs/full_guide.md

reconciliation: &reconciliation
  1_yarn:
    tags: reconciliation
    files: git diff --name-only HEAD main
    glob: '{package.json,yarn.lock}'
    run: make install_js_packages
    tags: frontend dependencies
  2_gem:
    tags: reconciliation
    files: git diff --name-only HEAD main
    glob: '{GEMFILE,GEMFILE.lock}'
    run: make bundle
    tags: backend dependencies

post-checkout:
  commands: *reconciliation
post-merge:
  commands: *reconciliation
post-rewrite:
  commands: *reconciliation

By default lefthook works as if piped: true was specified although it didn't crash on 0.8.0. I will see if we can prevent the crash and add a warning for config structure misuse. Thank you for reporting such a bug!

@mrexox
Copy link
Member

mrexox commented Jun 24, 2022

Will release the fix soon!

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.

2 participants