Return error as last value in BulkImport functions (#30575)

Этот коммит содержится в:
Ben Schumacher
2025-03-27 20:17:20 +01:00
коммит произвёл GitHub
родитель c03f339eca
Коммит 4156112f7c
5 изменённых файлов: 44 добавлений и 45 удалений

Просмотреть файл

@@ -181,11 +181,11 @@ func (a *App) bulkImportWorker(c request.CTX, dryRun, extractContent bool, wg *s
}
}
func (a *App) BulkImport(c request.CTX, jsonlReader io.Reader, attachmentsReader *zip.Reader, dryRun bool, workers int) (*model.AppError, int) {
func (a *App) BulkImport(c request.CTX, jsonlReader io.Reader, attachmentsReader *zip.Reader, dryRun bool, workers int) (int, *model.AppError) {
return a.bulkImport(c, jsonlReader, attachmentsReader, dryRun, true, workers, "")
}
func (a *App) BulkImportWithPath(c request.CTX, jsonlReader io.Reader, attachmentsReader *zip.Reader, dryRun, extractContent bool, workers int, importPath string) (*model.AppError, int) {
func (a *App) BulkImportWithPath(c request.CTX, jsonlReader io.Reader, attachmentsReader *zip.Reader, dryRun, extractContent bool, workers int, importPath string) (int, *model.AppError) {
return a.bulkImport(c, jsonlReader, attachmentsReader, dryRun, extractContent, workers, importPath)
}
@@ -193,7 +193,7 @@ func (a *App) BulkImportWithPath(c request.CTX, jsonlReader io.Reader, attachmen
// not nil. If it is nil, it will look for attachments on the
// filesystem in the locations specified by the JSONL file according
// to the older behavior
func (a *App) bulkImport(c request.CTX, jsonlReader io.Reader, attachmentsReader *zip.Reader, dryRun, extractContent bool, workers int, importPath string) (*model.AppError, int) {
func (a *App) bulkImport(c request.CTX, jsonlReader io.Reader, attachmentsReader *zip.Reader, dryRun, extractContent bool, workers int, importPath string) (int, *model.AppError) {
scanner := bufio.NewScanner(jsonlReader)
buf := make([]byte, 0, 64*1024)
scanner.Buffer(buf, maxScanTokenSize)
@@ -224,7 +224,7 @@ func (a *App) bulkImport(c request.CTX, jsonlReader io.Reader, attachmentsReader
var line imports.LineImportData
if err := json.Unmarshal(scanner.Bytes(), &line); err != nil {
return model.NewAppError("BulkImport", "app.import.bulk_import.json_decode.error", nil, "", http.StatusBadRequest).Wrap(err), lineNumber
return lineNumber, model.NewAppError("BulkImport", "app.import.bulk_import.json_decode.error", nil, "", http.StatusBadRequest).Wrap(err)
}
if err := processAttachments(c, &line, importPath, attachedFiles); err != nil {
@@ -234,11 +234,11 @@ func (a *App) bulkImport(c request.CTX, jsonlReader io.Reader, attachmentsReader
if lineNumber == 1 {
importDataFileVersion, appErr := processImportDataFileVersionLine(line)
if appErr != nil {
return appErr, lineNumber
return lineNumber, appErr
}
if importDataFileVersion != 1 {
return model.NewAppError("BulkImport", "app.import.bulk_import.unsupported_version.error", nil, "", http.StatusBadRequest), lineNumber
return lineNumber, model.NewAppError("BulkImport", "app.import.bulk_import.unsupported_version.error", nil, "", http.StatusBadRequest)
}
lastLineType = line.Type
continue
@@ -261,7 +261,7 @@ func (a *App) bulkImport(c request.CTX, jsonlReader io.Reader, attachmentsReader
if len(errorsChan) != 0 {
err := <-errorsChan
if stopOnError(c, err) {
return err.Error, err.LineNumber
return err.LineNumber, err.Error
}
}
}
@@ -288,7 +288,7 @@ func (a *App) bulkImport(c request.CTX, jsonlReader io.Reader, attachmentsReader
if stopOnError(c, err) {
close(linesChan)
wg.Wait()
return err.Error, err.LineNumber
return err.LineNumber, err.Error
}
}
}
@@ -303,15 +303,15 @@ func (a *App) bulkImport(c request.CTX, jsonlReader io.Reader, attachmentsReader
if len(errorsChan) != 0 {
err := <-errorsChan
if stopOnError(c, err) {
return err.Error, err.LineNumber
return err.LineNumber, err.Error
}
}
if err := scanner.Err(); err != nil {
return model.NewAppError("BulkImport", "app.import.bulk_import.file_scan.error", nil, "", http.StatusInternalServerError).Wrap(err), 0
return 0, model.NewAppError("BulkImport", "app.import.bulk_import.file_scan.error", nil, "", http.StatusInternalServerError).Wrap(err)
}
return nil, 0
return 0, nil
}
func processImportDataFileVersionLine(line imports.LineImportData) (int, *model.AppError) {