Skip to content

Commit

Permalink
improved error handling in case of bad function in template
Browse files Browse the repository at this point in the history
  • Loading branch information
ugol committed Jun 25, 2023
1 parent 481fe85 commit eb773e8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions pkg/emitter/emitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ func (e *Emitter) Initialize(conf configuration.GlobalConfiguration) {

keyTpl, err := tpl.NewTpl("key", e.KeyTemplate, functions.FunctionsMap(), &ctx.JrContext)
if err != nil {
log.Println(err)
log.Fatal(err)
}
valueTpl, err := tpl.NewTpl("value", e.EmbeddedTemplate, functions.FunctionsMap(), &ctx.JrContext)
if err != nil {
log.Println(err)
log.Fatal(err)
}

e.KTpl = keyTpl
Expand Down
14 changes: 7 additions & 7 deletions pkg/functions/functionsDescription.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ var funcDesc = map[string]FunctionDescription{
"from": {
Name: "from",
Category: "text utilities",
Description: "returns a random string from a list of strings in a file. Files are in '$HOME/.jr/templates/data/locale'",
Description: "returns a random string from a list of strings in a file. Files are in '$JR_HOME/templates/data/locale'",
Parameters: "set string",
Localizable: true,
Return: "string",
Expand All @@ -425,7 +425,7 @@ var funcDesc = map[string]FunctionDescription{
"from_at": {
Name: "from_at",
Category: "text utilities",
Description: "returns a string at a given position in a list of strings in a file. Files are in '$HOME/.jr/templates/data/locale'",
Description: "returns a string at a given position in a list of strings in a file. Files are in '$JR_HOME/templates/data/locale'",
Parameters: "index int",
Localizable: true,
Return: "string",
Expand All @@ -435,7 +435,7 @@ var funcDesc = map[string]FunctionDescription{
"from_n": {
Name: "from_n",
Category: "text utilities",
Description: "return a subset of elements in a list of string in a file. Files are in '$HOME/.jr/templates/data/locale'",
Description: "return a subset of elements in a list of string in a file. Files are in '$JR_HOME/templates/data/locale'",
Parameters: "set string, number int",
Localizable: true,
Return: "[]string",
Expand All @@ -445,7 +445,7 @@ var funcDesc = map[string]FunctionDescription{
"from_shuffle": {
Name: "from_shuffle",
Category: "text utilities",
Description: "returns a shuffled list of strings in a file. Files are in '$HOME/.jr/templates/data/locale'",
Description: "returns a shuffled list of strings in a file. Files are in '$JR_HOME/templates/data/locale'",
Parameters: "set string",
Localizable: true,
Return: "[]string",
Expand Down Expand Up @@ -639,7 +639,7 @@ var funcDesc = map[string]FunctionDescription{
Category: "text utilities",
Parameters: "set string",
Localizable: true,
Description: "returns the length a list of strings in a file. Files are in '$HOME/.jr/templates/data/locale'",
Description: "returns the length a list of strings in a file. Files are in '$JR_HOME/templates/data/locale'",
Return: "string",
Example: "jr template run --embedded '{{len \"city\"}}'",
Output: "46",
Expand Down Expand Up @@ -851,7 +851,7 @@ var funcDesc = map[string]FunctionDescription{
Parameters: "list []string",
Localizable: false,
Return: "string",
Example: "",
Example: "jr template run --embedded '{{dates_between \"1970-12-07\" \"1990-12-07\" 10 | random}}'",
Output: "hello",
},
"randoms": {
Expand All @@ -869,7 +869,7 @@ var funcDesc = map[string]FunctionDescription{
Category: "text utilities",
Parameters: "set string",
Localizable: true,
Description: "returns a random index from a list of strings in a file. Files are in '$HOME/.jr/templates/data/locale'",
Description: "returns a random index from a list of strings in a file. Files are in '$JR_HOME/templates/data/locale'",
Return: "string",
Example: "jr template run --embedded '{{random_index \"city\"}}'",
Output: "12",
Expand Down
2 changes: 1 addition & 1 deletion pkg/tpl/tpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (t *Tpl) ExecuteWith(data any) string {
var buffer bytes.Buffer
err := t.Template.Execute(&buffer, data)
if err != nil {
log.Println(err)
log.Fatal(err)
}
return buffer.String()
}
2 changes: 1 addition & 1 deletion testRest.http
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Content-Type: application/json
"preload": 0,
"valueTemplate": "net_device",
"output": "http",
"keyTemplate": "null",
"keyTemplate": "{{uuid}}",
"outputTemplate": "{{.V}}\n"
}

Expand Down

0 comments on commit eb773e8

Please sign in to comment.