Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions internals/panics.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package internals
import "fmt"

const (
PanicTypeCast = "Zog Panic: Type Cast Error\n Current context: %s\n Expected valPtr type to correspond with type defined in schema. But it does not. Expected type: *%T, got: %T\nFor more information see: https://zog.dev/panics#type-cast-errors"
PanicTypeCastCoercer = "Zog Panic: Type Cast Error\n Current context: %s\n Expected coercer return value to correspond with type defined in schema. But it does not. Expected type: *%T, got: %T\nFor more information see: https://zog.dev/panics#type-cast-errors"
PanicMissingStructField = "Zog Panic: Struct Schema Definition Error\n Current context: %s\n Provided struct is missing expected schema key: %s.\n This means you have made a mistake in your schema definition.\nFor more information see: https://zog.dev/panics#schema-definition-errors"
PanicTypeCast = "Zog Panic: Type Cast Error\n Current context: %s\n Expected valPtr type to correspond with type defined in schema. But it does not. Expected type: *%T, got: %T\nFor more information see: https://zog.dev/panics#type-cast-errors"
PanicTypeCastCoercer = "Zog Panic: Type Cast Error\n Current context: %s\n Expected coercer return value to correspond with type defined in schema. But it does not. Expected type: *%T, got: %T\nFor more information see: https://zog.dev/panics#type-cast-errors"
PanicMissingStructField = "Zog Panic: Struct Schema Definition Error\n Current context: %s\n Provided struct is missing expected schema key: %s.\n This means you have made a mistake in your schema definition.\nFor more information see: https://zog.dev/panics#schema-definition-errors"
PanicInvalidArgumentsExpectedPointer = "Zog Panic: Expected destination value to be a pointer but it was not. This is generally caused by forgetting to pass a pointer to your Validate/Parse function. Do schema.Validate(&myStruct), not schema.Validate(myStruct) "
)

func Panicf(format string, args ...any) {
Expand Down
7 changes: 6 additions & 1 deletion struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@ func (v *StructSchema) process(ctx *p.SchemaCtx) {
}

// 3. Process / validate struct fields
structVal := reflect.ValueOf(ctx.ValPtr).Elem()
structRefVal := reflect.ValueOf(ctx.ValPtr)
kind := structRefVal.Kind()
if kind != reflect.Pointer && kind != reflect.Interface {
p.Panicf(p.PanicInvalidArgumentsExpectedPointer)
}
structVal := structRefVal.Elem()
subCtx := ctx.NewSchemaCtx(ctx.Data, ctx.ValPtr, ctx.Path, v.getType())
defer subCtx.Free()
for key, processor := range v.schema {
Expand Down
Loading