Skip to content

Commit c611826

Browse files
committed
feat: use the more maintained YAML parsing lib at https://github.com/goccy/go-yaml
https://github.com/go-yaml/yaml has several issues pending and it appers that it is no longer maintained. e.g.: mikefarah/yq#2294 The general recommendation is to switch to a more maintained YAML parser implementation. CHANGELOG: - [ ] Switch to https://github.com/goccy/go-yaml since it is maintained
1 parent f802275 commit c611826

File tree

6 files changed

+91
-75
lines changed

6 files changed

+91
-75
lines changed

go/dotprompt/parse.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"slices"
2323
"strings"
2424

25-
"gopkg.in/yaml.v3"
25+
"github.com/goccy/go-yaml"
2626
)
2727

2828
// MessageSource is a message with a source string and optional content and
@@ -244,7 +244,18 @@ func ParseDocument(source string) (ParsedPrompt, error) {
244244

245245
if frontmatter != "" {
246246
var parsedMetadata map[string]any
247-
err := yaml.Unmarshal([]byte(frontmatter), &parsedMetadata)
247+
// The github.com/goccy/go-yaml library can panic on certain malformed YAML
248+
// so we need to use a custom error handler to recover from panics
249+
var err error
250+
func() {
251+
defer func() {
252+
if r := recover(); r != nil {
253+
err = fmt.Errorf("panic while parsing YAML: %v", r)
254+
}
255+
}()
256+
err = yaml.Unmarshal([]byte(frontmatter), &parsedMetadata)
257+
}()
258+
248259
if err != nil {
249260
fmt.Printf("Dotprompt: Error parsing YAML frontmatter: %v\n", err)
250261
// Return a basic ParsedPrompt with just the template

go/dotprompt/test/spec_parser_func.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ import (
2020
"fmt"
2121
"testing"
2222

23+
"github.com/goccy/go-yaml"
2324
dp "github.com/google/dotprompt/go/dotprompt"
2425
"github.com/invopop/jsonschema"
25-
"gopkg.in/yaml.v3"
2626
)
2727

2828
// convertToSpecSuite converts the YAML content into a slice of SpecSuite objects.

go/go.mod

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ module github.com/google/dotprompt/go
22

33
go 1.22.0
44

5+
toolchain go1.24.1
6+
57
require (
68
github.com/aymerick/raymond v2.0.2+incompatible
79
github.com/go-viper/mapstructure/v2 v2.2.1
10+
github.com/goccy/go-yaml v1.16.0
811
github.com/stretchr/testify v1.10.0
9-
gopkg.in/yaml.v2 v2.4.0 // indirect
10-
gopkg.in/yaml.v3 v3.0.1
1112
)
1213

1314
require (
@@ -22,4 +23,6 @@ require (
2223
github.com/bahlo/generic-list-go v0.2.0 // indirect
2324
github.com/buger/jsonparser v1.1.1 // indirect
2425
github.com/mailru/easyjson v0.9.0 // indirect
26+
gopkg.in/yaml.v2 v2.4.0 // indirect
27+
gopkg.in/yaml.v3 v3.0.1 // indirect
2528
)

go/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
88
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
99
github.com/go-viper/mapstructure/v2 v2.2.1 h1:ZAaOCxANMuZx5RCeg0mBdEZk7DZasvvZIxtHqx8aGss=
1010
github.com/go-viper/mapstructure/v2 v2.2.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
11+
github.com/goccy/go-yaml v1.16.0 h1:d7m1G7A0t+logajVtklHfDYJs2Et9g3gHwdBNNFou0w=
12+
github.com/goccy/go-yaml v1.16.0/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
1113
github.com/invopop/jsonschema v0.13.0 h1:KvpoAJWEjR3uD9Kbm2HWJmqsEaHt8lBUpd0qHcIi21E=
1214
github.com/invopop/jsonschema v0.13.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uON45H2qjYt+0=
1315
github.com/mailru/easyjson v0.9.0 h1:PrnmzHw7262yW8sTBwxi1PdJA3Iw/EKBa8psRf7d9a4=

python/handlebarrz/Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)