Skip to content

workflowcheck crash (index out of range) #1906

@Bysmyyr

Description

@Bysmyyr

Expected Behavior

No crash when running with -debug=f or through golangci-lint

Actual Behavior

It crashes: (happens with other codebases too but for the simplicity, running it with this codebase)

contrib/tools/workflowcheck on  master
❯ go run main.go -debug=f ./...
panic: runtime error: index out of range [0] with length 0

goroutine 2756 [running]:
golang.org/x/tools/go/analysis/internal/checker.(*action).exportPackageFact(0xc01346ed20, {0x849a88, 0xc010375d40})
	/home/olli/go/pkg/mod/golang.org/x/[email protected]/go/analysis/internal/checker/checker.go:963 +0x309
go.temporal.io/sdk/contrib/tools/workflowcheck/determinism.(*collector).applyFacts(0xc00ca16e40)
	/home/olli/Downloads/sdk-go/contrib/tools/workflowcheck/determinism/checker.go:427 +0x3ec
go.temporal.io/sdk/contrib/tools/workflowcheck/determinism.(*Checker).Run(0xc0000b51c0, 0xc0057ea460)
	/home/olli/Downloads/sdk-go/contrib/tools/workflowcheck/determinism/checker.go:202 +0x646
go.temporal.io/sdk/contrib/tools/workflowcheck/workflow.(*Checker).Run(0xc0000906c0, 0xc0057ea460)
	/home/olli/Downloads/sdk-go/contrib/tools/workflowcheck/workflow/checker.go:157 +0x117
go.temporal.io/sdk/contrib/tools/workflowcheck/workflow.(*Checker).NewAnalyzer.func1(0x7fffc5da3579?)
	/home/olli/Downloads/sdk-go/contrib/tools/workflowcheck/workflow/checker.go:129 +0x1d
golang.org/x/tools/go/analysis/internal/checker.(*action).execOnce(0xc01346ed20)
	/home/olli/go/pkg/mod/golang.org/x/[email protected]/go/analysis/internal/checker/checker.go:759 +0xad0
sync.(*Once).doSlow(0xc006b70030?, 0xc007fb04b0?)
	/home/olli/go/go1.24.1/src/sync/once.go:78 +0xab
sync.(*Once).Do(...)
	/home/olli/go/go1.24.1/src/sync/once.go:69
golang.org/x/tools/go/analysis/internal/checker.(*action).exec(...)
	/home/olli/go/pkg/mod/golang.org/x/[email protected]/go/analysis/internal/checker/checker.go:666
golang.org/x/tools/go/analysis/internal/checker.execAll.func1(0x0?)
	/home/olli/go/pkg/mod/golang.org/x/[email protected]/go/analysis/internal/checker/checker.go:654 +0x3b
created by golang.org/x/tools/go/analysis/internal/checker.execAll in goroutine 2747
	/home/olli/go/pkg/mod/golang.org/x/[email protected]/go/analysis/internal/checker/checker.go:660 +0x191
exit status 2

We found the issue when integrating the check for golangci-lint. With golangci-lint it crash always.

golangCI-lint has its own pass which does this always:

    act.Err = errorutil.NewPanicError(fmt.Sprintf("%s: package %q (isInitialPkg: %t, needAnalyzeSource: %t): %s",
       act.Analyzer.Name, act.Package.Name, act.isInitialPkg, act.needAnalyzeSource, p), debug.Stack())
}

when run on its own, it uses go standard reporter which does that only when debug flag is on, with it it fails:

if dbg('f') {
    fmt.Fprintf(os.Stderr, "%s: package %s has fact %s\n",
       act.pkg.Fset.Position(act.pass.Files[0].Pos()), act.pass.Pkg.Path(), fact)
}

Somehow the act.pass.Files is empty slice. In this case the key is package unsafe ("unsafe").

Steps to Reproduce the Problem

  1. cd contrib/tools/workflowcheck
  2. go run main.go -debug=f ./...

Specifications

  • Version: master (b9afba9)
  • Platform: go version go1.24.1 linux/amd64

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions