Repos / s4g / f5e7a6b694
commit f5e7a6b694fe1d92a1cf669fe820c7218b4a7563
Author: Nhân <hi@imnhan.com>
Date: Thu Jul 20 17:22:52 2023 +0700
rename UserFileErr to UserErr
diff --git a/errs/errs.go b/errs/errs.go
index 6ad5572..2614757 100644
--- a/errs/errs.go
+++ b/errs/errs.go
@@ -7,7 +7,7 @@
// Represents a user input error, which in webmaker2000's case is almost
// always some malformed file.
-type UserFileErr struct {
+type UserErr struct {
File string
Msg string
@@ -21,14 +21,14 @@ type UserFileErr struct {
Field string
}
-func (e *UserFileErr) Error() string {
+func (e *UserErr) Error() string {
return fmt.Sprintf(
"UserFileErr: %s - %d:%d:%s %s",
e.File, e.Line, e.Column, e.Field, e.Msg,
)
}
-func (e *UserFileErr) Html() template.HTML {
+func (e *UserErr) Html() template.HTML {
content := fmt.Sprintf("In file <b>%s</b>", e.File)
if e.Line != 0 {
content += fmt.Sprintf(", line %d", e.Line)
diff --git a/livereload/error.go b/livereload/error.go
index ac929ec..5750618 100644
--- a/livereload/error.go
+++ b/livereload/error.go
@@ -22,7 +22,7 @@ type errTmplInput struct {
func serveError(w http.ResponseWriter, r *http.Request, e error) {
var buf bytes.Buffer
- var uerr *errs.UserFileErr
+ var uerr *errs.UserErr
ok := errors.As(e, &uerr)
var tmplInput errTmplInput
diff --git a/main.go b/main.go
index 95f00f1..be06e87 100644
--- a/main.go
+++ b/main.go
@@ -211,7 +211,7 @@ func regenerate(fsys writablefs.FS) (site *SiteMetadata, err error) {
for _, link := range site.NavbarLinks {
a, ok := articles[link]
if !ok {
- return nil, &errs.UserFileErr{
+ return nil, &errs.UserErr{
File: SiteFileName,
Field: "NavbarLinks",
Msg: fmt.Sprintf(`"%s" does not exist`, link),
diff --git a/metadata.go b/metadata.go
index 2952388..0b5a3f4 100644
--- a/metadata.go
+++ b/metadata.go
@@ -65,7 +65,7 @@ func ReadSiteMetadata(fsys writablefs.FS) (*SiteMetadata, error) {
}
// Similar API to json.Unmarshal but supports neither struct tags nor nesting.
-func UnmarshalMetadata(data []byte, dest any) *errs.UserFileErr {
+func UnmarshalMetadata(data []byte, dest any) *errs.UserErr {
m := metaTextToMap(data)
s := reflect.ValueOf(dest).Elem()
@@ -82,7 +82,7 @@ func UnmarshalMetadata(data []byte, dest any) *errs.UserFileErr {
case "int":
intVal, err := strconv.Atoi(val)
if err != nil {
- return &errs.UserFileErr{
+ return &errs.UserErr{
Field: fieldName,
Msg: fmt.Sprintf(`invalid int: "%s"`, err),
}
@@ -91,7 +91,7 @@ func UnmarshalMetadata(data []byte, dest any) *errs.UserFileErr {
case "bool":
if val != "true" && val != "false" {
- return &errs.UserFileErr{
+ return &errs.UserErr{
Field: fieldName,
Msg: fmt.Sprintf(
`invalid boolean: expected true/false, got "%s"`,
@@ -105,7 +105,7 @@ func UnmarshalMetadata(data []byte, dest any) *errs.UserFileErr {
tVal, err := time.ParseInLocation("2006-01-02", val, time.Local)
tVal = tVal.Local()
if err != nil {
- return &errs.UserFileErr{
+ return &errs.UserErr{
Field: fieldName,
Msg: fmt.Sprintf(
`invalid date: expected YYYY-MM-DD, got "%s"`, val,