mirror of
https://codeberg.org/StreamGraph/StreamGraph.git
synced 2024-11-13 19:49:55 +01:00
715086f204
Reviewed-on: https://codeberg.org/StreamGraph/StreamGraph/pulls/92 Co-authored-by: Lera Elvoé <yagich@poto.cafe> Co-committed-by: Lera Elvoé <yagich@poto.cafe>
33 lines
970 B
GDScript
33 lines
970 B
GDScript
class_name ZodotResult
|
|
|
|
enum Result {
|
|
Ok, ## Value is valid
|
|
TypeError, ## Value does not match desired type
|
|
ConstraintError, ## Value does not satisfy constraint
|
|
Unknown ## Not parsed yet
|
|
}
|
|
|
|
var value: Result = Result.Unknown
|
|
var error: String = ""
|
|
var data: Variant
|
|
|
|
func ok() -> bool:
|
|
return value == Result.Ok
|
|
|
|
static func good(data: Variant) -> ZodotResult:
|
|
var result = ZodotResult.new()
|
|
result.value = Result.Ok
|
|
result.data = data
|
|
return result
|
|
|
|
static func type_error(field: String) -> ZodotResult:
|
|
var result = ZodotResult.new()
|
|
result.value = Result.TypeError
|
|
result.error = "Field '{field}' does not match desired type".format({ "field": field })
|
|
return result
|
|
|
|
static func constraint_error(field: String, detail: String = "") -> ZodotResult:
|
|
var result = ZodotResult.new()
|
|
result.value = Result.ConstraintError
|
|
result.error = "Field '{field}' does not satisfy constraint. {detail}".format({ "field": field, "detail": detail })
|
|
return result
|