Skip to content

Commit

Permalink
fix: template error issues and better reporting.
Browse files Browse the repository at this point in the history
  • Loading branch information
gchiesa committed Aug 3, 2024
1 parent b78daed commit 51eb60c
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ require (
github.com/nishanths/predeclared v0.2.2 // indirect
github.com/nunnatsa/ginkgolinter v0.16.2 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/palantir/stacktrace v0.0.0-20161112013806-78658fd2d177 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,8 @@ github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT9
github.com/otiai10/mint v1.3.1/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH1OTc=
github.com/otiai10/mint v1.5.1 h1:XaPLeE+9vGbuyEHem1JNk3bYc7KKqyI/na0/mLd/Kks=
github.com/otiai10/mint v1.5.1/go.mod h1:MJm72SBthJjz8qhefc4z1PYEieWmy8Bku7CjcAqyUSM=
github.com/palantir/stacktrace v0.0.0-20161112013806-78658fd2d177 h1:nRlQD0u1871kaznCnn1EvYiMbum36v7hw1DLPEjds4o=
github.com/palantir/stacktrace v0.0.0-20161112013806-78658fd2d177/go.mod h1:ao5zGxj8Z4x60IOVYZUbDSmt3R8Ddo080vEgPosHpak=
github.com/pelletier/go-buffruneio v0.2.0/go.mod h1:JkE26KsDizTr40EUHkXVtNPvgGtbSNq5BcowyYOWdKo=
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
Expand Down
9 changes: 9 additions & 0 deletions internal/multipart/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ func (mp *Multipart) Compile(forceRecompile bool) []byte {
}

func (mp *Multipart) CompileToFile(filePath string, forceRecompile bool) error {
// if local file exists, we need to use that as content
if _, err := os.Stat(filePath); err == nil {
dataContent, err := os.ReadFile(filePath)
if err != nil {
return err
}
mp.contentOriginal = dataContent
}
// otherwise we use the multipart content
dataContent := mp.Compile(forceRecompile)
return os.WriteFile(filePath, dataContent, 0o644)
}
2 changes: 1 addition & 1 deletion internal/processor/filetreeprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (tp *FileTreeProcessor) Cleanup() error {
func (tp *FileTreeProcessor) Render(withVariables map[string]interface{}) error {
if tp.workingDir == "" {
var err error
tp.workingDir, err = os.MkdirTemp("", "swansonRenderer")
tp.workingDir, err = os.MkdirTemp("", "skaRenderer")
if err != nil {
return err
}
Expand Down
5 changes: 5 additions & 0 deletions internal/processor/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ func (tp *FileTreeProcessor) shouldProcessFile(path string, ignoreList []string)
return false
}

// .DS_Store is always skipped
if path == ".DS_Store" {
return false
}

// skip internally generated files
fileParts := strings.Split(path, configuration.AppIdentifier)

Expand Down
5 changes: 3 additions & 2 deletions internal/templateservice/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package templateservice

import (
sprig "github.com/go-task/slim-sprig"
"github.com/palantir/stacktrace"
"io"
"os"
"strings"
Expand Down Expand Up @@ -36,7 +37,7 @@ func (t *SprigTemplate) FromString(templateContent string) error {
t.templateContent = templateContent
tpl, err := t.textTemplate.Parse(t.templateContent)
if err != nil {
return err
return stacktrace.Propagate(err, "failed to parse template")
}
t.textTemplate = tpl
return nil
Expand All @@ -51,7 +52,7 @@ func (t *SprigTemplate) FromFile(templateFilePath string) error {
t.templateContent = string(fileContent)
tpl, err := t.textTemplate.Parse(t.templateContent)
if err != nil {
return err
return stacktrace.Propagate(err, "failed to parse template")
}
t.textTemplate = tpl
return nil
Expand Down

0 comments on commit 51eb60c

Please sign in to comment.