go-zero icon indicating copy to clipboard operation
go-zero copied to clipboard

About goctl not working after upgrade

Open RanX12 opened this issue 7 months ago • 12 comments

goctl upgrade after version: v1.7.2

run: goctl upgrade or go install github.com/zeromicro/go-zero/tools/goctl@latest

executing any goctl command will result in the following

goctl --version
[1]    36328 killed     goctl --version

Later I had to switch back to the original version, and it worked immediately: go install github.com/zeromicro/go-zero/tools/[email protected]

RanX12 avatar Apr 30 '25 01:04 RanX12

I guess you're using gvm?

kevwan avatar May 02 '25 05:05 kevwan

Here are some detailed troubleshooting steps and potential solutions:

Possible causes and solutions:

  1. Memory limits or architecture incompatibility:

    • The killed message typically indicates the process was terminated by the OS, often due to memory issues or a segmentation fault.
  2. GVM (Go Version Manager) conflicts:

    • If you're using GVM, there might be conflicts with the Go environment settings.
    • Try temporarily disabling GVM and installing with a standard Go installation.
  3. Dependency conflicts:

    • Try clearing the Go module cache and reinstalling:
      go clean -modcache
      go install github.com/zeromicro/go-zero/tools/goctl@latest
      
  4. Compatibility with your OS/architecture:

    • What OS and architecture are you using? The latest version might have issues with specific platforms.
    • Try building from source to see if it resolves the issue:
      git clone https://github.com/zeromicro/go-zero.git
      cd go-zero/tools/goctl
      go build -o goctl main.go
      # Move the binary to your PATH
      
  5. Check for core dumps:

    • If your OS generates core dumps, check for them and submit them with your issue to help diagnose the problem.
    • On macOS/Linux: ulimit -c unlimited before running goctl can enable core dumps.
  6. Runtime environment:

    • Try to capture the full environment when the crash occurs:
      env | grep GO
      which goctl
      go version
      
  7. Pinning to a stable version:

    • As a temporary workaround, you can pin to the last stable version while the issue is being investigated:
      go install github.com/zeromicro/go-zero/tools/goctl@latest
      
  8. CGO related issues:

    • Try disabling CGO to see if it helps:
      CGO_ENABLED=0 go install github.com/zeromicro/go-zero/tools/goctl@latest
      

kevwan avatar May 02 '25 05:05 kevwan

@kevwan 最新版生成 types.go 文件存在问题,使用 v1.8.2 时是正常的 使用 v1.8.3 时报错

Xiphin avatar May 05 '25 06:05 Xiphin

@kevwan 最新版生成 types.go 文件存在问题,使用 v1.8.2 时是正常的 使用 v1.8.3 时报错

export GOCTL_EXPERIMENTAL=off

voidint avatar May 05 '25 06:05 voidint

@kevwan 最新版生成 types.go 文件存在问题,使用 v1.8.2 时是正常的 使用 v1.8.3 时报错

export GOCTL_EXPERIMENTAL=off

设置了,没用,生成路径错误,types.go 正常应该生成的路径:app/demo/rest/internal/types/types.go ,v1.8.3 生成报如下错误:

goctl api go --api=app/demo/rest/demo.api --dir=app/demo/rest/

app/demo/rest/etc/demo-api.yaml exists, ignored generation app/demo/rest/internal/config/config.go exists, ignored generation app/demo/rest/demo.go exists, ignored generation app/demo/rest/internal/svc/servicecontext.go exists, ignored generation 2025/05/05 15:39:30 open app/demo/rest/internal/types/adminapi/demo/demo.go: no such file or directory

goroutine 1 [running]: runtime/debug.Stack() /opt/homebrew/Cellar/go/1.24.2/libexec/src/runtime/debug/stack.go:26 +0x64 github.com/zeromicro/go-zero/core/logx.Must({0x1019ac398?, 0x14000473b60?}) /Users/XiaoMing/Go/pkg/mod/github.com/zeromicro/[email protected]/core/logx/logs.go:268 +0x40 github.com/zeromicro/go-zero/tools/goctl/api/gogen.DoGenProject({0x14000122156, 0x1c}, {0x1400012c936, 0x11}, {0x101332bcd, 0x6}, 0x0) /Users/XiaoMing/Go/pkg/mod/github.com/zeromicro/go-zero/tools/[email protected]/api/gogen/gen.go:100 +0x148 github.com/zeromicro/go-zero/tools/goctl/api/gogen.GoCommand(0x14000148b00?, {0x1013304b6?, 0x4?, 0x1013303b6?}) /Users/XiaoMing/Go/pkg/mod/github.com/zeromicro/go-zero/tools/[email protected]/api/gogen/gen.go:71 +0x160 github.com/spf13/cobra.(*Command).execute(0x14000164308, {0x140002dd420, 0x2, 0x2}) /Users/XiaoMing/Go/pkg/mod/github.com/spf13/[email protected]/command.go:1015 +0x828 github.com/spf13/cobra.(*Command).ExecuteC(0x140000fa908) /Users/XiaoMing/Go/pkg/mod/github.com/spf13/[email protected]/command.go:1148 +0x350 github.com/spf13/cobra.(*Command).Execute(...) /Users/XiaoMing/Go/pkg/mod/github.com/spf13/[email protected]/command.go:1071 github.com/zeromicro/go-zero/tools/goctl/cmd.Execute() /Users/XiaoMing/Go/pkg/mod/github.com/zeromicro/go-zero/tools/[email protected]/cmd/root.go:47 +0x7c main.main() /Users/XiaoMing/Go/pkg/mod/github.com/zeromicro/go-zero/tools/[email protected]/goctl.go:12 +0x60

Xiphin avatar May 05 '25 07:05 Xiphin

echo $GOCTL_EXPERIMENTAL

off

Xiphin avatar May 05 '25 07:05 Xiphin

@kevwan 最新版生成 types.go 文件存在问题,使用 v1.8.2 时是正常的 使用 v1.8.3 时报错

export GOCTL_EXPERIMENTAL=off

not export GOCTL_EXPERIMENTAL=off, but goctl env -w GOCTL_EXPERIMENTAL=off

kesonan avatar May 05 '25 08:05 kesonan

@kevwan 最新版生成 types.go 文件存在问题,使用 v1.8.2 时是正常的 使用 v1.8.3 时报错

export GOCTL_EXPERIMENTAL=off

not export GOCTL_EXPERIMENTAL=off, but goctl env -w GOCTL_EXPERIMENTAL=off

可行,可以用了

Xiphin avatar May 05 '25 08:05 Xiphin

没设置时, 提示 no such file or directory 功能是不是还需要优化一下,没有目录自动创建对应目录

Xiphin avatar May 05 '25 08:05 Xiphin

@Xiphin pls Add my wechat iikeson, let me reproduce this bug

方便加一下我的微信吗,微信号 iikeson, 我看一下你的 api 怎么定义的,我复现一下。

kesonan avatar May 05 '25 08:05 kesonan

@Xiphin pls Add my wechat iikeson, let me reproduce this bug

方便加一下我的微信吗,微信号 iikeson, 我看一下你的 api 怎么定义的,我复现一下。

加你了 通过一下

Xiphin avatar May 05 '25 08:05 Xiphin

@kevwan 最新版生成 types.go 文件存在问题,使用 v1.8.2 时是正常的 使用 v1.8.3 时报错

it fixed on pr #4849

kesonan avatar May 11 '25 02:05 kesonan