|
@@ -11,6 +11,7 @@ import (
|
|
|
|
|
|
"git.wecise.com/wecise/cgimport/cgf/reader"
|
|
|
"git.wecise.com/wecise/util/filewalker"
|
|
|
+ "git.wecise.com/wecise/util/merrs"
|
|
|
"git.wecise.com/wecise/util/rc"
|
|
|
)
|
|
|
|
|
@@ -54,35 +55,38 @@ func ImportDir(datapath string, parallel int) (filescount, recordscount int64, e
|
|
|
func ImportFile(filepath string) (blockcount int, err error) {
|
|
|
f, e := os.Open(filepath)
|
|
|
if e != nil {
|
|
|
- return blockcount, e
|
|
|
+ return blockcount, merrs.NewError(e, merrs.SSMaps{{"filename": filepath}})
|
|
|
}
|
|
|
defer f.Close()
|
|
|
- return importReader(f)
|
|
|
+ return importReader(filepath, f)
|
|
|
}
|
|
|
|
|
|
-func importReader(buf io.Reader) (blockcount int, err error) {
|
|
|
- br := reader.NewBlockReader(buf)
|
|
|
+func importReader(filename string, buf io.Reader) (blockcount int, err error) {
|
|
|
+ br, e := reader.NewBlockReader(filename, buf)
|
|
|
+ if e != nil {
|
|
|
+ return blockcount, merrs.NewError(e, merrs.SSMaps{{"filename": filename}})
|
|
|
+ }
|
|
|
for {
|
|
|
- block, e := br.ReadBlock()
|
|
|
+ block, linecount, e := br.ReadBlock()
|
|
|
if e != nil {
|
|
|
- return blockcount, e
|
|
|
+ return blockcount, merrs.NewError(e, merrs.SSMaps{{"filename": filename}, {"line": fmt.Sprint(linecount)}})
|
|
|
}
|
|
|
if block == nil {
|
|
|
return
|
|
|
}
|
|
|
- e = importBlock(block)
|
|
|
+ e = importBlock(block, filename, linecount)
|
|
|
if e != nil {
|
|
|
- return blockcount, e
|
|
|
+ return blockcount, merrs.NewError(e, merrs.SSMaps{{"filename": filename}, {"line": fmt.Sprint(linecount)}})
|
|
|
}
|
|
|
blockcount++
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func importBlock(block map[string]any) (err error) {
|
|
|
+func importBlock(block map[string]any, filename string, linecount int) (err error) {
|
|
|
bs, e := json.MarshalIndent(block, "", " ")
|
|
|
if e != nil {
|
|
|
return e
|
|
|
}
|
|
|
- fmt.Println("import:", string(bs))
|
|
|
+ fmt.Println(fmt.Sprint("import ", filename, "[", linecount, "]:", string(bs)))
|
|
|
return
|
|
|
}
|