Skip to content
Snippets Groups Projects
Select Git revision
  • fdde2d5f841f263d70b48f0d99f2edbc2374e2d7
  • release default
  • 11-22-implement-kv-interface-defined-in-collectiveversionedkvgo
  • master protected
  • XX-4688/DbEncoding
  • hotfix/update
  • @XX-4682/Files
  • hotfix/XX-4655
  • dev protected
  • project/HavenNotifications
  • XX-4602/SilentMessageType
  • jono/npmTest
  • wasmTest2
  • XX-4461/FileUpload
  • XX-4505/blockuser
  • XX-4441
  • Jakub/Emoji-CI-Test
  • testing/websockets
  • fastReg
  • fast-registration
  • NewHostPool
  • v0.3.22
  • v0.3.21
  • v0.3.20
  • v0.3.18
  • v0.3.17
  • v0.3.16
  • v0.3.15
  • v0.3.14
  • v0.3.13
  • v0.3.12
  • v0.3.11
  • v0.3.10
  • v0.3.9
  • v0.3.8
  • v0.3.7
  • v0.3.6
  • v0.3.5
  • v0.3.4
  • 812b395df518ce096d01d5292596ca26f8fe92d9c4487ddfa515e190a51aa1a1
  • 76ba08e2dfa1798412a265404fa271840b52c035869111fce8e8cdb23a036a5a
41 results

errors.go

  • errors.go 2.47 KiB
    ////////////////////////////////////////////////////////////////////////////////
    // Copyright © 2022 xx foundation                                             //
    //                                                                            //
    // Use of this source code is governed by a license that can be found in the  //
    // LICENSE file.                                                              //
    ////////////////////////////////////////////////////////////////////////////////
    
    //go:build js && wasm
    
    package utils
    
    import (
    	"fmt"
    	"syscall/js"
    )
    
    // JsError converts the error to a Javascript Error.
    func JsError(err error) js.Value {
    	return Error.New(err.Error())
    }
    
    // JsTrace converts the error to a Javascript Error that includes the error's
    // stack trace.
    func JsTrace(err error) js.Value {
    	return Error.New(fmt.Sprintf("%+v", err))
    }
    
    // Throw function stub to throws Javascript exceptions. The exception must be
    // one of the defined Exception below. Any other error types will result in an
    // error.
    func Throw(exception Exception, err error) {
    	throw(exception, fmt.Sprintf("%+v", err))
    }
    
    func throw(exception Exception, message string)
    
    // Exception are the possible Javascript error types that can be thrown.
    type Exception string
    
    const (
    	// EvalError occurs when error has occurred in the eval() function.
    	//
    	// Deprecated: This exception is not thrown by JavaScript anymore, however
    	// the EvalError object remains for compatibility.
    	EvalError Exception = "EvalError"
    
    	// RangeError occurs when a numeric variable or parameter is outside its
    	// valid range.
    	RangeError Exception = "RangeError"
    
    	// ReferenceError occurs when a variable that does not exist (or hasn't yet
    	// been initialized) in the current scope is referenced.
    	ReferenceError Exception = "ReferenceError"
    
    	// SyntaxError occurs when trying to interpret syntactically invalid code.
    	SyntaxError Exception = "SyntaxError"
    
    	// TypeError occurs when an operation could not be performed, typically (but
    	// not exclusively) when a value is not of the expected type.
    	//
    	// A TypeError may be thrown when:
    	//  - an operand or argument passed to a function is incompatible with the
    	//    type expected by that operator or function; or
    	//  - when attempting to modify a value that cannot be changed; or
    	//  - when attempting to use a value in an inappropriate way.
    	TypeError Exception = "TypeError"
    
    	// URIError occurs when a global URI handling function was used in a wrong
    	// way.
    	URIError Exception = "URIError"
    )