Skip to content

Commit

Permalink
add reproduction code of syumai/workers#100
Browse files Browse the repository at this point in the history
  • Loading branch information
syumai committed Apr 16, 2024
1 parent fbe6822 commit f271ed4
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 0 deletions.
3 changes: 3 additions & 0 deletions syumai-workers-repro-issue-100/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build
node_modules
.wrangler
12 changes: 12 additions & 0 deletions syumai-workers-repro-issue-100/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.PHONY: dev
dev:
wrangler dev

.PHONY: build
build:
go run github.com/syumai/workers/cmd/[email protected] -mode=go
GOOS=js GOARCH=wasm go build -o ./build/app.wasm .

.PHONY: deploy
deploy:
wrangler deploy
35 changes: 35 additions & 0 deletions syumai-workers-repro-issue-100/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# syumai-workers-repro-issue-100

* A reproduction code of https://github.com/syumai/workers/issues/100

## Reproduction code

* A HandlerFunc without writing response body causes weird error.

```go
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
// doing nothing here causes weird error
})
workers.Serve(nil) // use http.DefaultServeMux
}
```

## How to reproduce

```
$ make dev # run this command in another terminal
$ curl localhost:8787
TypeError: Cannot read properties of undefined (reading 'exports')
at syscall/js.valueNew (file:///home/syumai/go/src/github.com/syumai/workers-playground/syumai-workers-repro-issue-100/build/wasm_exec.js:395:24)
at [object Object]
at [object Object]
at [object Object]
at [object Object]
at [object Object]
at globalThis.Go._resume (file:///home/syumai/go/src/github.com/syumai/workers-playground/syumai-workers-repro-issue-100/build/wasm_exec.js:553:23)
at Object.handleRequest (file:///home/syumai/go/src/github.com/syumai/workers-playground/syumai-workers-repro-issue-100/build/wasm_exec.js:564:8)
at Object.fetch (file:///home/syumai/go/src/github.com/syumai/workers-playground/syumai-workers-repro-issue-100/build/shim.mjs:51:18)
at async jsonError (file:///home/syumai/.nvm/versions/node/v20.12.2/lib/node_modules/wrangler/templates/middleware/middleware-miniflare3-json-error.ts:22:10)
```

7 changes: 7 additions & 0 deletions syumai-workers-repro-issue-100/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module github.com/syumai/workers-playground/syumai-workers-repro-issue-100

go 1.21.3

toolchain go1.22.2

require github.com/syumai/workers v0.23.3
2 changes: 2 additions & 0 deletions syumai-workers-repro-issue-100/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/syumai/workers v0.23.3 h1:7RZwe+EhOhLlFvrDMbgWFf2wc/G17i4uq4GsSG0uNrI=
github.com/syumai/workers v0.23.3/go.mod h1:ZnqmdiHNBrbxOLrZ/HJ5jzHy6af9cmiNZk10R9NrIEA=
14 changes: 14 additions & 0 deletions syumai-workers-repro-issue-100/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package main

import (
"net/http"

"github.com/syumai/workers"
)

func main() {
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
// doing nothing here causes weird error
})
workers.Serve(nil) // use http.DefaultServeMux
}
6 changes: 6 additions & 0 deletions syumai-workers-repro-issue-100/wrangler.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name = "go-worker"
main = "./build/worker.mjs"
compatibility_date = "2024-04-15"

[build]
command = "make build"

0 comments on commit f271ed4

Please sign in to comment.