don't os.exit anymore as often

This commit is contained in:
Jeff Carr 2024-12-15 17:03:51 -06:00
parent 24ddb803f3
commit 8e9408bac8
5 changed files with 46 additions and 24 deletions

View File

@ -2,6 +2,8 @@
package main
import (
"errors"
"fmt"
"os"
"strings"
"time"
@ -51,15 +53,16 @@ func doRelease() bool {
return false
}
if !me.forge.FinalGoDepsCheckOk(check) {
log.Info("the go.mod file is wrong. fix it here?", check.GetGoPath())
os.Exit(-1)
msg := fmt.Sprint("the go.mod file is wrong. fix it here?", check.GetGoPath())
badExit(errors.New(msg))
return false
}
if check.GoPath == me.startRepo.GoPath {
log.Info("CAN NOT SELF UPDATE.", check.GoPath, "is the same as os.Getwd()")
log.Info("go get must be run from somewhere else other than startRepo")
log.Info("chdir to autotypist if it exists")
os.Exit(-1)
msg := fmt.Sprint("CAN NOT SELF UPDATE.", check.GoPath, "is the same as os.Getwd()")
badExit(errors.New(msg))
}
if !me.startRepo.Exists("go.mod") {
log.Info("go.sum missing in", me.startRepo.GoPath)
@ -73,7 +76,8 @@ func doRelease() bool {
if err := check.ValidGoSum(); err != nil {
log.Info("ValidGoSum() error", check.GoPath, err)
os.Exit(-1)
msg := fmt.Sprint("ValidGoSum() error", check.GoPath, err)
badExit(errors.New(msg))
}
var all [][]string
@ -91,7 +95,8 @@ func doRelease() bool {
if err != nil {
log.Info("\tERROR: There are protobuf files, but they are not compiled")
log.Info("\tERROR: can not continue")
os.Exit(-1)
msg := fmt.Sprint("ERROR: There are protobuf files, but they are not compiled")
badExit(errors.New(msg))
}
log.Info("\tshould add the protobuf files here")
log.Info("\tcompiled files found:", compiled)
@ -112,7 +117,8 @@ func doRelease() bool {
cname := check.GetCurrentBranchName()
if err := check.AutogenSave(autogen, cname, true); err != nil {
log.Info("AutogenSave() error", err)
os.Exit(-1)
msg := fmt.Sprint("AutogenSave() error", err)
badExit(errors.New(msg))
}
if !me.current.Status.DoAll(all) {
@ -145,7 +151,6 @@ func doRelease() bool {
}
}
*/
me.forge.Repos.ConfigSave()
}
log.Info("PUBLISH OK")
@ -181,7 +186,8 @@ func doRelease() bool {
newtag := me.release.version.String()
if err := check.AutogenSave(autogen, newtag, true); err != nil {
log.Info("AutogenSave() error", err)
os.Exit(-1)
msg := fmt.Sprint("AutogenSave() error", err)
badExit(errors.New(msg))
}
// it's necessary to recreate the the files here
@ -253,7 +259,8 @@ func doPublishVersion() bool {
log.Info("CAN NOT SELF UPDATE. cmd =", docmd)
log.Info("go get must be run from somewhere else other than startRepo")
log.Info("chdir to autotypist if it exists")
os.Exit(-1)
msg := fmt.Sprint("CAN NOT SELF UPDATE. cmd =", docmd)
badExit(errors.New(msg))
}
// publish go.mod & go.sum for use with go
os.Unsetenv("GO111MODULE")

18
exit.go Normal file
View File

@ -0,0 +1,18 @@
package main
import (
"os"
"go.wit.com/log"
)
func okExit(thing string) {
log.Info(thing, "ok")
// log.Info("Finished go-clean on", check.GetGoPath(), "ok")
os.Exit(0)
}
func badExit(err error) {
log.Info("forge failed: ", err, me.forge.GetGoSrc())
os.Exit(-1)
}

View File

@ -1,6 +1,7 @@
package main
import (
"errors"
"fmt"
"net/http"
"os"
@ -178,10 +179,6 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
case "/releaseList":
PrintReleaseReport(readonly, perfect)
return
case "/quit":
log.Info("Got URL /quit")
os.Exit(0)
return
case "/goweblist":
loop := me.repos.View.ReposAll()
for loop.Scan() {
@ -289,8 +286,8 @@ func showNext() {
if ok, compiled, err := me.current.IsProtobuf(); ok {
log.Info(log.Sprint("IsProtobuf() == true compiled protobuf files = ", compiled))
if err != nil {
log.Info(log.Sprint("IsProtobuf() == err", err))
os.Exit(-1)
msg := fmt.Sprint("IsProtobuf() == err", err)
badExit(errors.New(msg))
}
for _, s := range compiled {
log.Info("\tcompiled file found:", s)

12
main.go
View File

@ -2,6 +2,8 @@ package main
import (
"embed"
"errors"
"fmt"
"os"
"path/filepath"
"strings"
@ -35,8 +37,7 @@ func main() {
me.releaseReasonS = os.Getenv("GUIRELEASE_REASON")
if me.releaseReasonS == "" {
log.Info("shell ENV GUIRELEASE_REASON not set")
os.Exit(0)
badExit(errors.New("shell ENV GUIRELEASE_REASON not set"))
}
// unset the go development ENV var to generate release files
@ -62,8 +63,7 @@ func main() {
homeDir, _ := os.UserHomeDir()
gowork := filepath.Join(homeDir, "go/src/go.work")
if shell.Exists(gowork) {
log.Info("go.work must be deleted")
os.Exit(0)
badExit(errors.New("go.work must be deleted"))
}
log.Info("Creating the Release Window")
@ -118,8 +118,8 @@ func main() {
me.startRepo = me.forge.Repos.FindByGoPath(basedir)
if me.startRepo == nil {
log.Info("Can not run if pwd is not a repo", basedir)
os.Exit(0)
msg := fmt.Sprint("Can not run if pwd is not a repo", basedir)
badExit(errors.New(msg))
}
me.Enable()

View File

@ -139,7 +139,7 @@ func createReleaseBox(box *gui.Node) {
log.Info("doReleaseAll() first =", first, "second =", second)
if first == 0 {
log.Info("doReleaseAll() first is 0. everything is done")
log.Info("os.Exit(0) here safely")
log.Info("exit() here safely")
buttonEnable()
return
}
@ -159,6 +159,7 @@ func createReleaseBox(box *gui.Node) {
if (second == 0) && (third == 0) {
log.Info("doReleaseAll() SaveConfig() here and Exit(0)")
me.forge.ConfigSave()
okExit("")
}
} else {
log.Info("doReleaseAll() first second match. something has gone terribly wrong")
@ -253,12 +254,11 @@ func doReleaseAll() (bool, time.Duration) {
if os.Getenv("FindNextDone") == "true" {
log.Info("findNext says it was done. findCounter =", findCounter)
log.Info("findNext says it was done. findCounter =", findCounter)
log.Info("we can os.Exit here")
log.Info("we can exit here")
}
if me.release.status.String() == "ALL DONE?" {
log.Info("maybe ALL DONE?. findCounter =", findCounter)
worked = true
// os.Exit(0)
}
log.Info("doRelease() failed. findCounter =", findCounter)
worked = false