updated serve command error reporting

This commit is contained in:
Gani Georgiev 2024-01-24 11:06:49 +02:00
parent eaf121ead7
commit 2862119c1f
1 changed files with 9 additions and 7 deletions

View File

@ -2,7 +2,6 @@ package cmd
import ( import (
"errors" "errors"
"log"
"net/http" "net/http"
"github.com/pocketbase/pocketbase/apis" "github.com/pocketbase/pocketbase/apis"
@ -18,10 +17,11 @@ func NewServeCommand(app core.App, showStartBanner bool) *cobra.Command {
var httpsAddr string var httpsAddr string
command := &cobra.Command{ command := &cobra.Command{
Use: "serve [domain(s)]", Use: "serve [domain(s)]",
Args: cobra.ArbitraryArgs, Args: cobra.ArbitraryArgs,
Short: "Starts the web server (default to 127.0.0.1:8090 if no domain is specified)", Short: "Starts the web server (default to 127.0.0.1:8090 if no domain is specified)",
Run: func(command *cobra.Command, args []string) { SilenceUsage: true,
RunE: func(command *cobra.Command, args []string) error {
// set default listener addresses if at least one domain is specified // set default listener addresses if at least one domain is specified
if len(args) > 0 { if len(args) > 0 {
if httpAddr == "" { if httpAddr == "" {
@ -44,9 +44,11 @@ func NewServeCommand(app core.App, showStartBanner bool) *cobra.Command {
CertificateDomains: args, CertificateDomains: args,
}) })
if !errors.Is(err, http.ErrServerClosed) { if errors.Is(err, http.ErrServerClosed) {
log.Fatalln(err) return nil
} }
return err
}, },
} }