MCPcopy Create free account
hub / github.com/buke/quickjs-go / ToError

Method ToError

value.go:481–518  ·  view source on GitHub ↗

ToError returns the error value of the value.

()

Source from the content-addressed store, hash-verified

479
480// ToError returns the error value of the value.
481func (v *Value) ToError() error {
482 if !v.IsError() {
483 return nil
484 }
485
486 err := &Error{}
487
488 name := v.Get("name")
489 defer name.Free()
490 if !name.IsUndefined() {
491 err.Name = name.ToString()
492 }
493
494 message := v.Get("message")
495 defer message.Free()
496 if !message.IsUndefined() {
497 err.Message = message.ToString()
498 }
499
500 cause := v.Get("cause")
501 defer cause.Free()
502 if !cause.IsUndefined() {
503 err.Cause = cause.ToString()
504 }
505
506 stack := v.Get("stack")
507 defer stack.Free()
508 if !stack.IsUndefined() {
509 err.Stack = stack.ToString()
510 }
511
512 jsonString := v.JSONStringify()
513 if jsonString != "" {
514 err.JSONString = jsonString
515 }
516
517 return err
518}
519
520// propertyEnum is a wrapper around JSValue.
521func (v *Value) propertyEnum() ([]*propertyEnum, error) {

Callers 2

ErrorMethod · 0.95
TestValueErrorFunction · 0.80

Calls 6

IsErrorMethod · 0.95
GetMethod · 0.95
JSONStringifyMethod · 0.95
IsUndefinedMethod · 0.80
FreeMethod · 0.45
ToStringMethod · 0.45

Tested by 1

TestValueErrorFunction · 0.64