Skip to content
Snippets Groups Projects
Verified Commit 752d3af5 authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

feat: add new UIError #65

parent c99c7406
No related branches found
No related tags found
No related merge requests found
......@@ -6,11 +6,12 @@
package jobqueue
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
"testing"
"time"
)
func TestWriteToDB1(t *testing.T) {
......
......@@ -8,58 +8,64 @@ import (
)
var (
ErrMissingDependency = fmt.Errorf("missing dependency")
ErrCycleDetected = fmt.Errorf("cycle detected")
ErrQueueEmpty = fmt.Errorf("queue is empty")
ErrJobAlreadyExists = fmt.Errorf("job already exists")
ErrWorkerNotRunning = fmt.Errorf("worker is not running")
ErrMaxJobsReached = fmt.Errorf("maximum number of jobs reached")
ErrWorkerAlreadyRunning = fmt.Errorf("worker is already running")
ErrWorkerAlreadyAdded = fmt.Errorf("worker is already added")
ErrWorkerNotAdded = fmt.Errorf("worker is not added")
ErrNoWorkers = fmt.Errorf("no workers")
ErrWorkerAlreadyStopped = fmt.Errorf("worker is already stopped")
ErrManagerAlreadyStopped = fmt.Errorf("manager is already stopped")
ErrManagerAlreadyRunning = fmt.Errorf("manager is already running")
ErrManagerNotRunning = fmt.Errorf("manager is not running")
ErrJobNotScheduled = fmt.Errorf("job is not scheduled")
ErrCronNotInitialized = fmt.Errorf("cron is not initialized")
ErrCPUPercentage = fmt.Errorf("cpu percentage must be between 0 and 100")
ErrIntervalIsZero = fmt.Errorf("interval must be greater than 0")
ErrUnknownRunnableType = fmt.Errorf("unknown runnable type")
ErrUnknownSchedulerType = fmt.Errorf("unknown scheduler type")
ErrUnsupportedDatabaseType = fmt.Errorf("unsupported database type")
ErrUnsupportedFileOption = fmt.Errorf("unsupported file option")
ErrUnsupportedCredentialType = fmt.Errorf("unsupported credential type")
ErrUnsupportedTransferDirection = fmt.Errorf("unsupported transfer direction")
ErrInvalidData = fmt.Errorf("invalid data")
ErrUnknownFormat = fmt.Errorf("unknown format")
ErrFailedToCreateTempFile = fmt.Errorf("failed to create temp file")
ErrFailedToWriteTempFile = fmt.Errorf("failed to write temp file")
ErrJobAlreadyScheduled = fmt.Errorf("job already scheduled")
ErrNoDatabaseConnection = fmt.Errorf("no database connection")
ErrDBSaverNotRunning = fmt.Errorf("dbsaver is not running")
ErrDBSaverNotInitialized = fmt.Errorf("dbsaver is not initialized")
ErrSchedulerNotSet = fmt.Errorf("scheduler is not set")
ErrJobNotActive = fmt.Errorf("job is not active")
ErrJobAlreadyActive = fmt.Errorf("job is already active")
ErrChannelAlreadyClosed = fmt.Errorf("the channel is already closed")
ErrUnknownScheduleType = fmt.Errorf("unknown schedule type")
ErrNoManager = fmt.Errorf("no manager")
ErrCannotLoadStatsFromDatabase = fmt.Errorf("errors while loading stats from database")
ErrInvalidTime = fmt.Errorf("invalid time")
ErrSchedulerMisconfiguration = fmt.Errorf("scheduler misconfiguration")
ErrInvalidDuration = fmt.Errorf("invalid duration")
ErrJobSyncerAlreadyRunning = fmt.Errorf("JobSyncer is already running")
ErrJobSyncerNotRunning = fmt.Errorf("JobSyncer is not running")
ErrMaxRetriesReached = fmt.Errorf("maximum number of retries reached")
ErrTimeoutReached = fmt.Errorf("timeout reached")
ErrFailedToCreate = fmt.Errorf("failed to create")
ErrFailedToQueryExistingJob = fmt.Errorf("failed to query an existing job")
ErrFailedToSaveJob = fmt.Errorf("failed to save a job")
ErrScheduleTimeIsInThePast = fmt.Errorf("scheduled time is in the past")
ErrParameterIsNil = fmt.Errorf("parameter is nil")
ErrJobIDEmpty = fmt.Errorf("job ID is empty")
ErrManagerNotInitialized = fmt.Errorf("manager is not initialized")
ErrJobSyncerNotInitialized = fmt.Errorf("JobSyncer is not initialized")
ErrMissingDependency = newUIError("missing dependency")
ErrCycleDetected = newUIError("cycle detected")
ErrQueueEmpty = newUIError("queue is empty")
ErrJobAlreadyExists = newUIError("job already exists")
ErrWorkerNotRunning = newUIError("worker is not running")
ErrMaxJobsReached = newUIError("maximum number of jobs reached")
ErrWorkerAlreadyRunning = newUIError("worker is already running")
ErrWorkerAlreadyAdded = newUIError("worker is already added")
ErrWorkerNotAdded = newUIError("worker is not added")
ErrNoWorkers = newUIError("no workers")
ErrWorkerAlreadyStopped = newUIError("worker is already stopped")
ErrManagerAlreadyStopped = newUIError("manager is already stopped")
ErrManagerAlreadyRunning = newUIError("manager is already running")
ErrManagerNotRunning = newUIError("manager is not running")
ErrJobNotScheduled = newUIError("job is not scheduled")
ErrCronNotInitialized = newUIError("cron is not initialized")
ErrCPUPercentage = newUIError("cpu percentage must be between 0 and 100")
ErrIntervalIsZero = newUIError("interval must be greater than 0")
ErrUnknownRunnableType = newUIError("unknown runnable type")
ErrUnknownSchedulerType = newUIError("unknown scheduler type")
ErrUnsupportedDatabaseType = newUIError("unsupported database type")
ErrUnsupportedFileOption = newUIError("unsupported file option")
ErrUnsupportedCredentialType = newUIError("unsupported credential type")
ErrUnsupportedTransferDirection = newUIError("unsupported transfer direction")
ErrInvalidData = newUIError("invalid data")
ErrUnknownFormat = newUIError("unknown format")
ErrFailedToCreateTempFile = newUIError("failed to create temp file")
ErrFailedToWriteTempFile = newUIError("failed to write temp file")
ErrJobAlreadyScheduled = newUIError("job already scheduled")
ErrNoDatabaseConnection = newUIError("no database connection")
ErrSchedulerNotSet = newUIError("scheduler is not set")
ErrJobNotActive = newUIError("job is not active")
ErrJobAlreadyActive = newUIError("job is already active")
ErrChannelAlreadyClosed = newUIError("the channel is already closed")
ErrUnknownScheduleType = newUIError("unknown schedule type")
ErrCannotLoadStatsFromDatabase = newUIError("errors while loading stats from database")
ErrInvalidTime = newUIError("invalid time")
ErrSchedulerMisconfiguration = newUIError("scheduler misconfiguration")
ErrMaxRetriesReached = newUIError("maximum number of retries reached")
ErrTimeoutReached = newUIError("timeout reached")
ErrFailedToCreate = newUIError("failed to create")
ErrFailedToQueryExistingJob = newUIError("failed to query an existing job")
ErrFailedToSaveJob = newUIError("failed to save a job")
ErrParameterIsNil = newUIError("parameter is nil")
ErrJobIDEmpty = newUIError("job ID is empty")
ErrManagerNotInitialized = newUIError("manager is not initialized")
ErrScheduleTimeIsInThePast = newUIError("scheduled time is in the past")
)
// UIError is an error that can be displayed to the user
type UIError struct {
msg string
}
func newUIError(msg string, args ...any) *UIError {
return &UIError{msg: fmt.Sprintf(msg, args...)}
}
func (e *UIError) Error() string {
return e.msg
}
......@@ -5,6 +5,7 @@ package jobqueue
import (
"encoding/json"
"errors"
"fmt"
"github.com/robfig/cron/v3"
"gopkg.in/yaml.v3"
......@@ -247,11 +248,8 @@ func ReadFromGORM(db *gorm.DB) ([]JobPersistence, error) {
}
if len(wrappedErr) > 0 {
returnErr := ErrCannotLoadStatsFromDatabase
for _, err := range wrappedErr {
returnErr = fmt.Errorf("%w: %v", returnErr, err)
}
return returnErr
wrappedErr = append(wrappedErr, ErrCannotLoadStatsFromDatabase)
return errors.Join(wrappedErr...)
}
return nil
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment