Shopify / themekit

Shopify theme development command line tool.
https://shopify.dev/tools/theme-kit
MIT License
1.19k stars 375 forks source link

Mysterious crash when watching #140

Closed ilikeorangutans closed 8 years ago

ilikeorangutans commented 8 years ago

Got a mysterious crash when watching via @stevebosworth !

panic: runtime error: slice bounds out of range

goroutine 10 [running]:
github.com/ryanuber/go-glob.Glob(0xc20802b868, 0x5, 0x0, 0x0, 0xc208a946c0)
    /Users/steveb/Codes/golang/src/github.com/shopify/themekit/Godeps/_workspace/src/github.com/ryanuber/go-glob/glob.go:54 +0x4ca
github.com/Shopify/themekit.EventFilter.MatchesFilter(0xc208036840, 0x5, 0x8, 0xc20801f680, 0x2, 0x2, 0x0, 0x0, 0x7)
    /Users/steveb/codes/golang/src/github.com/Shopify/themekit/event_filter.go:103 +0x161
github.com/Shopify/themekit.func·008()
    /Users/steveb/codes/golang/src/github.com/Shopify/themekit/file_watcher.go:158 +0x101
created by github.com/Shopify/themekit.convertFsEvents
    /Users/steveb/codes/golang/src/github.com/Shopify/themekit/file_watcher.go:169 +0x14a

goroutine 1 [chan receive, 1181 minutes]:
main.main()
    /Users/steveb/codes/golang/src/github.com/Shopify/themekit/cmd/theme/main.go:145 +0x413

goroutine 5 [chan receive, 1183 minutes]:
github.com/Shopify/themekit.func·002()
    /Users/steveb/codes/golang/src/github.com/Shopify/themekit/error_reporter.go:50 +0x52
created by github.com/Shopify/themekit.SetErrorReporter
    /Users/steveb/codes/golang/src/github.com/Shopify/themekit/error_reporter.go:56 +0x69

goroutine 9 [runnable]:
gopkg.in/fsnotify%2ev1.(*Watcher).readEvents(0xc20803e3c0)
    /Users/steveb/Codes/golang/src/github.com/shopify/themekit/Godeps/_workspace/src/gopkg.in/fsnotify.v1/kqueue.go:301 +0x711
created by gopkg.in/fsnotify%2ev1.NewWatcher
    /Users/steveb/Codes/golang/src/github.com/shopify/themekit/Godeps/_workspace/src/gopkg.in/fsnotify.v1/kqueue.go:61 +0x31f

goroutine 11 [select]:
github.com/Shopify/themekit/bucket.func·001()
    /Users/steveb/codes/golang/src/github.com/Shopify/themekit/bucket/leaky_bucket.go:35 +0x104
created by github.com/Shopify/themekit/bucket.(*LeakyBucket).StartDripping
    /Users/steveb/codes/golang/src/github.com/Shopify/themekit/bucket/leaky_bucket.go:42 +0x8c

goroutine 12 [select]:
github.com/Shopify/themekit.func·011()
    /Users/steveb/codes/golang/src/github.com/Shopify/themekit/foreman.go:33 +0x218
created by github.com/Shopify/themekit.Foreman.IssueWork
    /Users/steveb/codes/golang/src/github.com/Shopify/themekit/foreman.go:50 +0xa0

goroutine 13 [chan receive]:
github.com/Shopify/themekit/commands.spawnWorker(0xc208062330, 0x24, 0xc20803f5c0, 0x0, 0xc20801ea40, 0x20, 0xc20801eac0, 0x1a, 0xc20800b230, 0x28, ...)
    /Users/steveb/codes/golang/src/github.com/Shopify/themekit/commands/watch.go:81 +0xba
created by github.com/Shopify/themekit/commands.watchForChangesAndIssueWork
    /Users/steveb/codes/golang/src/github.com/Shopify/themekit/commands/watch.go:74 +0x3c1

goroutine 14 [chan receive]:
github.com/Shopify/themekit/commands.spawnWorker(0xc208062360, 0x24, 0xc20803f5c0, 0x0, 0xc20801ea40, 0x20, 0xc20801eac0, 0x1a, 0xc20800b230, 0x28, ...)
    /Users/steveb/codes/golang/src/github.com/Shopify/themekit/commands/watch.go:81 +0xba
created by github.com/Shopify/themekit/commands.watchForChangesAndIssueWork
    /Users/steveb/codes/golang/src/github.com/Shopify/themekit/commands/watch.go:74 +0x3c1

goroutine 15 [select]:
main.func·001()
    /Users/steveb/codes/golang/src/github.com/Shopify/themekit/cmd/theme/main.go:130 +0x2b7
created by main.main
    /Users/steveb/codes/golang/src/github.com/Shopify/themekit/cmd/theme/main.go:143 +0x3c5

goroutine 33 [syscall, 1183 minutes, locked to thread]:
runtime.goexit()
    /usr/local/Cellar/go/1.4.2/libexec/src/runtime/asm_amd64.s:2232 +0x1```
ilikeorangutans commented 8 years ago

Did some preliminary digging here. Turns out the way event_filter.go works is that it attempts to parse all ignore_files settings into regexps. The ones that cannot be parsed into a regex will be parsed into a glob. Now, turns out that this glob doesn't like empty string inputs which makes it crash.

Interesting questions to investigate further are

  1. why is the input empty? Could it be that the root directory we're watching got touched?
  2. why does an empty string make glob crash? Maybe we need to file a bug report.