forgejo/models/actions/pre_execution_errors.go

42 lines
1.5 KiB
Go
Raw Normal View History

// Copyright 2025 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: GPL-3.0-or-later
package actions
import (
"fmt"
"forgejo.org/modules/translation"
)
type PreExecutionError int64
// PreExecutionError values are stored in the database in ActionRun.PreExecutionError and therefore values can't be
// reordered or changed without a database migration. Translation arguments are stored in the database in
// PreExecutionErrorDetails, and so they can't be changed or reordered without creating a migration or a new error code
// to represent the new argument details.
const (
ErrorCodeEventDetectionError PreExecutionError = iota + 1
ErrorCodeJobParsingError
ErrorCodePersistentIncompleteMatrix
)
func TranslatePreExecutionError(lang translation.Locale, run *ActionRun) string {
if run.PreExecutionError != "" {
// legacy: Forgejo v13 stored value pre-translated, preventing correct translation to active user
return run.PreExecutionError
}
switch run.PreExecutionErrorCode {
case 0:
return ""
case ErrorCodeEventDetectionError:
return lang.TrString("actions.workflow.event_detection_error", run.PreExecutionErrorDetails...)
case ErrorCodeJobParsingError:
return lang.TrString("actions.workflow.job_parsing_error", run.PreExecutionErrorDetails...)
case ErrorCodePersistentIncompleteMatrix:
return lang.TrString("actions.workflow.persistent_incomplete_matrix", run.PreExecutionErrorDetails...)
}
return fmt.Sprintf("<unsupported error: code=%v details=%#v", run.PreExecutionErrorCode, run.PreExecutionErrorDetails)
}