capture errors from libxml2

fixes #4
This commit is contained in:
Ross Kinder
2015-12-23 17:17:48 -05:00
parent c095422255
commit dc37ddb368
6 changed files with 48 additions and 25 deletions

View File

@@ -4,6 +4,7 @@ import (
"C"
"fmt"
"runtime"
"strings"
"github.com/crewjam/errset"
)
@@ -32,8 +33,8 @@ func (e libraryError) Error() string {
e.Message)
}
//export onError
func onError(file *C.char, line C.int, funcName *C.char, errorObject *C.char, errorSubject *C.char, reason C.int, msg *C.char) {
//export onXmlsecError
func onXmlsecError(file *C.char, line C.int, funcName *C.char, errorObject *C.char, errorSubject *C.char, reason C.int, msg *C.char) {
err := libraryError{
FuncName: C.GoString(funcName),
FileName: C.GoString(file),
@@ -46,6 +47,13 @@ func onError(file *C.char, line C.int, funcName *C.char, errorObject *C.char, er
globalErrors[threadID] = append(globalErrors[threadID], err)
}
//export onXmlError
func onXmlError(msg *C.char) {
threadID := getThreadID()
globalErrors[threadID] = append(globalErrors[threadID],
fmt.Errorf("%s", strings.TrimSuffix(C.GoString(msg), "\n")))
}
// startProcessingXML is called whenever we enter a function exported by this package.
// It locks the current goroutine to the current thread and establishes a thread-local
// error object. If the library later calls onError then the error will be appended