MM-46990 Report correct import error (#21025)

Этот коммит содержится в:
Tim Scheuermann
2022-09-21 12:15:33 +02:00
коммит произвёл GitHub
родитель 6b4813899f
Коммит ad0705bbca
4 изменённых файлов: 30 добавлений и 1 удалений

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

@@ -5607,6 +5607,10 @@
"id": "app.job.download_export_results_not_enabled",
"translation": "DownloadExportResults in config.json is false. Please set this to true to download the results of this job."
},
{
"id": "app.job.error",
"translation": "Error during job execution."
},
{
"id": "app.job.get.app_error",
"translation": "Unable to get the job."

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

@@ -81,7 +81,7 @@ func (worker *SimpleWorker) DoJob(job *model.Job) {
err := worker.execute(job)
if err != nil {
mlog.Error("SimpleWorker: job execution error", mlog.String("worker", worker.name), mlog.String("job_id", job.Id), mlog.Err(err))
worker.setJobError(job, model.NewAppError("DoJob", "app.user.get_total_users_count.app_error", nil, "", http.StatusInternalServerError).Wrap(err))
worker.setJobError(job, model.NewAppError("DoJob", "app.job.error", nil, "", http.StatusInternalServerError).Wrap(err))
return
}

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

@@ -122,6 +122,9 @@ func (srv *JobServer) SetJobError(job *model.Job, jobError *model.AppError) *mod
if jobError.DetailedError != "" {
job.Data["error"] += " — " + jobError.DetailedError
}
if wrapped := jobError.Unwrap(); wrapped != nil {
job.Data["error"] += " — " + wrapped.Error()
}
updated, err := srv.Store.Job().UpdateOptimistically(job, model.JobStatusInProgress)
if err != nil {
return model.NewAppError("SetJobError", "app.job.update.app_error", nil, "", http.StatusInternalServerError).Wrap(err)

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

@@ -4,6 +4,8 @@
package jobs
import (
"errors"
"net/http"
"testing"
"github.com/stretchr/testify/require"
@@ -390,6 +392,26 @@ func TestSetJobError(t *testing.T) {
err := jobServer.SetJobError(job, jobError)
require.Nil(t, err)
})
t.Run("error message set correctly", func(t *testing.T) {
jobServer, mockStore, _ := makeJobServer(t)
jobError := model.NewAppError("anywhere", "not.a.valid.id", nil, "details", http.StatusTeapot).Wrap(errors.New("wrapped"))
job := &model.Job{
Id: "job_id",
Type: "job_type",
Progress: -1,
Data: map[string]string{},
}
mockStore.JobStore.On("UpdateOptimistically", job, model.JobStatusInProgress).Return(false, nil)
mockStore.JobStore.On("UpdateOptimistically", job, model.JobStatusCancelRequested).Return(true, nil)
err := jobServer.SetJobError(job, jobError)
require.Nil(t, err)
require.Equal(t, "not.a.valid.id — details — wrapped", job.Data["error"])
})
})
}