Skip to content

Commit

Permalink
It's errors and fatals only
Browse files Browse the repository at this point in the history
Ditch the concept of internal,
fatals are from templates,
errors are from ain.

Errors can be your fault
or the computers. Fatals
are exclusively yours.

Test plan:
* go run cmd/ain/main.go
  and verify error message
  still looks the same.
  • Loading branch information
jonaslu committed Oct 16, 2024
1 parent c752a0c commit 9d339b4
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions cmd/ain/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"strings"
"syscall"

"github.com/pkg/errors"

"github.com/jonaslu/ain/internal/app/ain"
"github.com/jonaslu/ain/internal/pkg/call"
"github.com/jonaslu/ain/internal/pkg/disk"
Expand All @@ -22,8 +20,8 @@ var gitSha = "develop"

const bashSignalCaughtBase = 128

func printInternalErrorAndExit(err error) {
formattedError := fmt.Sprintf("Error: %v", err.Error())
func printErrorAndExit(err error) {
formattedError := fmt.Sprintf("Error: %s", err.Error())
fmt.Fprintln(os.Stderr, formattedError)
os.Exit(1)
}
Expand All @@ -48,7 +46,7 @@ func main() {

if cmdParams.GenerateEmptyTemplate {
if err := disk.GenerateEmptyTemplates(); err != nil {
printInternalErrorAndExit(err)
printErrorAndExit(err)
}

return
Expand All @@ -66,17 +64,16 @@ func main() {
}

if err := disk.ReadEnvFile(cmdParams.EnvFile, cmdParams.EnvFile != ".env"); err != nil {
printInternalErrorAndExit(err)
printErrorAndExit(err)
}

localTemplateFileNames, err := disk.GetTemplateFilenames(cmdParams.TemplateFileNames)
if err != nil {
printInternalErrorAndExit(err)
printErrorAndExit(err)
}

if len(localTemplateFileNames) == 0 {
// !! TODO !! This is not an internal error
printInternalErrorAndExit(errors.New("Missing template file name(s)\n\nTry 'ain -h' for more information"))
printErrorAndExit(fmt.Errorf("missing template file name(s)\n\nTry 'ain -h' for more information"))
}

cancelCtx, cancel := context.WithCancel(context.Background())
Expand All @@ -94,7 +91,7 @@ func main() {
if err != nil {
checkSignalRaisedAndExit(assembledCtx, signalRaised)

printInternalErrorAndExit(err)
printErrorAndExit(err)
}

if fatal != "" {
Expand All @@ -109,7 +106,7 @@ func main() {

call, err := call.Setup(backendInput)
if err != nil {
printInternalErrorAndExit(err)
printErrorAndExit(err)
}

if cmdParams.PrintCommand {
Expand Down

0 comments on commit 9d339b4

Please sign in to comment.