Rename front matter errors to meta errors
This commit is contained in:
parent
847eff17b9
commit
37022e051a
10
error.go
10
error.go
@ -2,11 +2,11 @@ package step
|
|||||||
|
|
||||||
// Error enumerates errors common to this package.
|
// Error enumerates errors common to this package.
|
||||||
type Error string; const (
|
type Error string; const (
|
||||||
ErrCircularInheritance Error = "circular inheritance"
|
ErrCircularInheritance Error = "circular inheritance"
|
||||||
ErrFrontMatterMalformed Error = "front matter is malformed"
|
ErrMetaMalformed Error = "metadata is malformed"
|
||||||
ErrFrontMatterNeverClosed Error = "front matter is never closed"
|
ErrMetaNeverClosed Error = "metadata is never closed"
|
||||||
ErrFrontMatterDuplicateKey Error = "duplicate key in front matter"
|
ErrMetaDuplicateKey Error = "duplicate key in front matter"
|
||||||
ErrTypeMismatch Error = "type mismatch"
|
ErrTypeMismatch Error = "type mismatch"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Error fulfills the error interface.
|
// Error fulfills the error interface.
|
||||||
|
8
meta.go
8
meta.go
@ -27,7 +27,7 @@ func SplitMeta (input string) (Meta, string, error) {
|
|||||||
input = strings.TrimPrefix(input, frontMatterRule)
|
input = strings.TrimPrefix(input, frontMatterRule)
|
||||||
index := strings.Index(input, "\n" + frontMatterRule + "\n")
|
index := strings.Index(input, "\n" + frontMatterRule + "\n")
|
||||||
if index < 0 {
|
if index < 0 {
|
||||||
return nil, "", ErrFrontMatterNeverClosed
|
return nil, "", ErrMetaNeverClosed
|
||||||
}
|
}
|
||||||
frontMatterRaw := input[:index]
|
frontMatterRaw := input[:index]
|
||||||
body := input[index + len(frontMatterRule) + 2:]
|
body := input[index + len(frontMatterRule) + 2:]
|
||||||
@ -48,15 +48,15 @@ func ParseMeta (input string) (Meta, error) {
|
|||||||
if line == "" { continue }
|
if line == "" { continue }
|
||||||
key, value, ok := strings.Cut(line, ":")
|
key, value, ok := strings.Cut(line, ":")
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, ErrFrontMatterMalformed
|
return nil, ErrMetaMalformed
|
||||||
}
|
}
|
||||||
key = strings.ToLower(strings.TrimSpace(key))
|
key = strings.ToLower(strings.TrimSpace(key))
|
||||||
value = strings.TrimSpace(value)
|
value = strings.TrimSpace(value)
|
||||||
if key == "" {
|
if key == "" {
|
||||||
return nil, ErrFrontMatterMalformed
|
return nil, ErrMetaMalformed
|
||||||
}
|
}
|
||||||
if _, exists := meta[key]; exists {
|
if _, exists := meta[key]; exists {
|
||||||
return nil, ErrFrontMatterDuplicateKey
|
return nil, ErrMetaDuplicateKey
|
||||||
}
|
}
|
||||||
meta[key] = value
|
meta[key] = value
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user