Parcourir la source

prevent un handled panic in open xslx

fixes #137
fzerorubigd il y a 10 ans
Parent
commit
f9c709fad6
1 fichiers modifiés avec 13 ajouts et 0 suppressions
  1. 13 0
      lib.go

+ 13 - 0
lib.go

@@ -563,6 +563,19 @@ func readSheetViews(xSheetViews xlsxSheetViews) []SheetView {
 // sheet and get the results back on the provided channel.
 // sheet and get the results back on the provided channel.
 func readSheetFromFile(sc chan *indexedSheet, index int, rsheet xlsxSheet, fi *File, sheetXMLMap map[string]string) {
 func readSheetFromFile(sc chan *indexedSheet, index int, rsheet xlsxSheet, fi *File, sheetXMLMap map[string]string) {
 	result := &indexedSheet{Index: index, Sheet: nil, Error: nil}
 	result := &indexedSheet{Index: index, Sheet: nil, Error: nil}
+	defer func() {
+		if e := recover(); e != nil {
+			switch e.(type) {
+			case error:
+				result.Error = e.(error)
+			default:
+				result.Error = errors.New("unexpected error")
+			}
+			// The only thing here, is if one close the channel. but its not the case
+			sc <- result
+		}
+	}()
+
 	worksheet, error := getWorksheetFromSheet(rsheet, fi.worksheets, sheetXMLMap)
 	worksheet, error := getWorksheetFromSheet(rsheet, fi.worksheets, sheetXMLMap)
 	if error != nil {
 	if error != nil {
 		result.Error = error
 		result.Error = error