go-gitea / gitea

Git with a cup of tea! Painless self-hosted all-in-one software development service, including Git hosting, code review, team collaboration, package registry and CI/CD
https://gitea.com
MIT License
44.59k stars 5.45k forks source link

If not sign in compare will return error 500 #11423

Closed L0veSunshine closed 4 years ago

L0veSunshine commented 4 years ago

Description

When you don't sign in and click the compare button on repo's homepage, it will occur error 500

Screenshots

zeripath commented 4 years ago

Logs would have been helpful.

L0veSunshine commented 4 years ago

Logs would have been helpful.

please wait a minute and i have locate the question. maybe is here https://github.com/go-gitea/gitea/blob/57217cabe34e2a01fbb3cb93bd93fbefa38fee91/routers/repo/compare.go#L218

L0veSunshine commented 4 years ago

Here is the log

2020/05/14 12:57:18 ...les/context/panic.go:35:1() [E] PANIC:: runtime error: invalid memory address or nil pointer dereference /home/go/src/runtime/panic.go:212 (0x456c19) panicmem: panic(memoryError) /home/go/src/runtime/signal_unix.go:687 (0x456a68) sigpanic: panicmem() /home/gitea-sync/routers/repo/compare.go:218 (0x1991419) ParseCompareInfo: if ctx.User.ID != 0 { /home/gitea-sync/routers/repo/compare.go:521 (0x1994e7f) CompareDiff: headUser, headRepo, headGitRepo, compareInfo, baseBranch, headBranch := ParseCompareInfo(ctx) /home/go/src/reflect/value.go:460 (0x4a070a) Value.call: call(frametype, fn, args, uint32(frametype.size), uint32(retOffset)) /home/go/src/reflect/value.go:321 (0x49fc13) Value.Call: return v.call("Call", in) /home/gitea-sync/vendor/gitea.com/macaron/inject/inject.go:177 (0xc1b97b) (injector).callInvoke: return reflect.ValueOf(f).Call(in), nil /home/gitea-sync/vendor/gitea.com/macaron/inject/inject.go:137 (0xc1b359) (injector).Invoke: return inj.callInvoke(f, t, t.NumIn()) /home/gitea-sync/vendor/gitea.com/macaron/macaron/context.go:121 (0xc368a8) (Context).run: vals, err := c.Invoke(c.handler()) /home/gitea-sync/vendor/gitea.com/macaron/macaron/context.go:112 (0x116e06f) (Context).Next: c.run() /home/gitea-sync/modules/context/repo.go:579 (0x116e058) RepoAssignment.func1: ctx.Next() /home/go/src/reflect/value.go:460 (0x4a070a) Value.call: call(frametype, fn, args, uint32(frametype.size), uint32(retOffset)) /home/go/src/reflect/value.go:321 (0x49fc13) Value.Call: return v.call("Call", in) /home/gitea-sync/vendor/gitea.com/macaron/inject/inject.go:177 (0xc1b97b) (injector).callInvoke: return reflect.ValueOf(f).Call(in), nil /home/gitea-sync/vendor/gitea.com/macaron/inject/inject.go:137 (0xc1b359) (injector).Invoke: return inj.callInvoke(f, t, t.NumIn()) /home/gitea-sync/vendor/gitea.com/macaron/macaron/context.go:121 (0xc368a8) (Context).run: vals, err := c.Invoke(c.handler()) /home/gitea-sync/vendor/gitea.com/macaron/macaron/context.go:112 (0x116b964) (Context).Next: c.run() /home/gitea-sync/modules/context/panic.go:39 (0x116b955) Recovery.func1: ctx.Next() /home/go/src/reflect/value.go:460 (0x4a070a) Value.call: call(frametype, fn, args, uint32(frametype.size), uint32(retOffset)) /home/go/src/reflect/value.go:321 (0x49fc13) Value.Call: return v.call("Call", in) /home/gitea-sync/vendor/gitea.com/macaron/inject/inject.go:177 (0xc1b97b) (injector).callInvoke: return reflect.ValueOf(f).Call(in), nil /home/gitea-sync/vendor/gitea.com/macaron/inject/inject.go:137 (0xc1b359) (injector).Invoke: return inj.callInvoke(f, t, t.NumIn()) /home/gitea-sync/vendor/gitea.com/macaron/macaron/context.go:121 (0xc368a8) (Context).run: vals, err := c.Invoke(c.handler()) /home/gitea-sync/vendor/gitea.com/macaron/macaron/context.go:112 (0x1123935) (Context).Next: c.run() /home/gitea-sync/vendor/gitea.com/macaron/session/session.go:192 (0x1123920) Sessioner.func1: ctx.Next() /home/gitea-sync/vendor/gitea.com/macaron/macaron/context.go:79 (0xc36750) ContextInvoker.Invoke: invoke(params[0].(Context)) /home/gitea-sync/vendor/gitea.com/macaron/inject/inject.go:157 (0xc1b6a7) (injector).fastInvoke: return f.Invoke(in) /home/gitea-sync/vendor/gitea.com/macaron/inject/inject.go:135 (0xc1b448) (injector).Invoke: return inj.fastInvoke(v, t, t.NumIn()) /home/gitea-sync/vendor/gitea.com/macaron/macaron/context.go:121 (0xc368a8) (Context).run: vals, err := c.Invoke(c.handler()) /home/gitea-sync/vendor/gitea.com/macaron/macaron/context.go:112 (0xc47cd5) (Context).Next: c.run() /home/gitea-sync/vendor/gitea.com/macaron/macaron/recovery.go:161 (0xc47cc8) Recovery.func1: c.Next() /home/gitea-sync/vendor/gitea.com/macaron/macaron/logger.go:40 (0xc3a313) LoggerInvoker.Invoke: invoke(params[0].(Context), params[1].(log.Logger)) /home/gitea-sync/vendor/gitea.com/macaron/inject/inject.go:157 (0xc1b6a7) (injector).fastInvoke: return f.Invoke(in) /home/gitea-sync/vendor/gitea.com/macaron/inject/inject.go:135 (0xc1b448) (injector).Invoke: return inj.fastInvoke(v, t, t.NumIn()) /home/gitea-sync/vendor/gitea.com/macaron/macaron/context.go:121 (0xc368a8) (Context).run: vals, err := c.Invoke(c.handler()) /home/gitea-sync/vendor/gitea.com/macaron/macaron/context.go:112 (0xc47000) (Context).Next: c.run() /home/gitea-sync/vendor/gitea.com/macaron/macaron/logger.go:52 (0xc46feb) Logger.func1: ctx.Next() /home/gitea-sync/vendor/gitea.com/macaron/macaron/logger.go:40 (0xc3a313) LoggerInvoker.Invoke: invoke(params[0].(Context), params[1].(log.Logger)) /home/gitea-sync/vendor/gitea.com/macaron/inject/inject.go:157 (0xc1b6a7) (injector).fastInvoke: return f.Invoke(in) /home/gitea-sync/vendor/gitea.com/macaron/inject/inject.go:135 (0xc1b448) (injector).Invoke: return inj.fastInvoke(v, t, t.NumIn()) /home/gitea-sync/vendor/gitea.com/macaron/macaron/context.go:121 (0xc368a8) (Context).run: vals, err := c.Invoke(c.handler()) /home/gitea-sync/vendor/gitea.com/macaron/macaron/router.go:187 (0xc48ee6) (Router).Handle.func1: c.run() /home/gitea-sync/vendor/gitea.com/macaron/macaron/router.go:303 (0xc428e5) (Router).ServeHTTP: h(rw, req, p) /home/gitea-sync/vendor/gitea.com/macaron/macaron/macaron.go:218 (0xc3b66a) (Macaron).ServeHTTP: m.Router.ServeHTTP(rw, req) /home/gitea-sync/vendor/github.com/gorilla/context/context.go:141 (0xead023) ClearHandler.func1: h.ServeHTTP(w, r) /home/go/src/net/http/server.go:2012 (0x7582c3) HandlerFunc.ServeHTTP: f(w, r) /home/go/src/net/http/server.go:2807 (0x75b652) serverHandler.ServeHTTP: handler.ServeHTTP(rw, req) /home/go/src/net/http/server.go:1895 (0x7570cb) (conn).serve: serverHandler{c.server}.ServeHTTP(w, w.req) /home/go/src/runtime/asm_amd64.s:1373 (0x472c10) goexit: BYTE $0x90 // NOP

zeripath commented 4 years ago

Thanks I've already put up a fix - it was actually very simple to reproduce.

I unfortunately caused it.

L0veSunshine commented 4 years ago

Thanks I've already put up a fix - it was actually very simple to reproduce.

I unfortunately caused it.

The code in compare.go is really awful before your commit. By the way, your annotate is clearly and useful. Thanks for your pr.