Skip to content

Commit

Permalink
fix(profiles): Exit with an error if templating fails
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Feb 13, 2025
1 parent 45724b9 commit f96564d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions cmd/profiles/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package profiles

import (
"cmp"
"fmt"
"io"
"os"
"slices"
"strconv"
"strings"
Expand Down Expand Up @@ -89,8 +91,14 @@ func helpFunc(cmd *cobra.Command, _ []string) {
var buf strings.Builder
buf.Grow(v.Param)
tmpl, err := tmpl.New("").Parse(v.Template)
if err == nil {
_ = tmpl.Execute(&buf, v.Param)
if err != nil {
cmd.PrintErrln(cmd.ErrPrefix(), fmt.Errorf("failed to parse profile %q: %w", name, err))
os.Exit(1)
}

if err := tmpl.Execute(&buf, v.Param); err != nil {
cmd.PrintErrln(cmd.ErrPrefix(), fmt.Errorf("failed to execute profile %q: %w", name, err))
os.Exit(1)
}

switch format {
Expand Down

0 comments on commit f96564d

Please sign in to comment.