From 15916444e18c71c066ffe8a7cd37cf272ec115eb Mon Sep 17 00:00:00 2001 From: Gusted Date: Thu, 18 Jan 2024 14:31:46 +0000 Subject: [PATCH] Fix panic in formatting not found message (#276) Fix panic that was found in the logs, `targetOpt` is `nil`: http2: panic serving 10.0.3.1:[...]: runtime error: invalid memory address or nil pointer dereference net/http.(*http2serverConn).runHandler.func1() /usr/local/go/src/net/http/h2_bundle.go:6104 +0x145 panic({0x19c6820, 0x2d66db0}) /usr/local/go/src/runtime/panic.go:884 +0x213 codeberg.org/codeberg/pages/server/handler.handleSubDomain({{0x2008c68, 0xc00047df90}, 0x2, {0x0, 0x0}, {0xc0fe3ef800, 0x55, 0x1f4}, {0xc00047dfa0, 0x1, ...}, ...}, ...) /woodpecker/src/codeberg.org/Codeberg/pages-server/server/handler/handler_sub_domain.go:59 +0x5e0 Reviewed-on: https://codeberg.org/Codeberg/pages-server/pulls/276 Reviewed-by: crapStone Co-authored-by: Gusted Co-committed-by: Gusted --- server/handler/handler_sub_domain.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/handler/handler_sub_domain.go b/server/handler/handler_sub_domain.go index e7cb3a6..6c14393 100644 --- a/server/handler/handler_sub_domain.go +++ b/server/handler/handler_sub_domain.go @@ -57,7 +57,7 @@ func handleSubDomain(log zerolog.Logger, ctx *context.Context, giteaClient *gite } else { html.ReturnErrorPage( ctx, - formatSetBranchNotFoundMessage(targetOpt.TargetBranch, targetOpt.TargetOwner, targetOpt.TargetRepo), + formatSetBranchNotFoundMessage(pathElements[1][1:], targetOwner, pathElements[0]), http.StatusFailedDependency, ) } @@ -89,7 +89,7 @@ func handleSubDomain(log zerolog.Logger, ctx *context.Context, giteaClient *gite } else { html.ReturnErrorPage( ctx, - formatSetBranchNotFoundMessage(targetOpt.TargetBranch, targetOpt.TargetOwner, targetOpt.TargetRepo), + formatSetBranchNotFoundMessage(targetBranch, targetOwner, defaultPagesRepo), http.StatusFailedDependency, ) }