mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2026-02-17 21:47:02 +02:00
Identified in code review https://codeberg.org/forgejo/forgejo/pulls/10244#issuecomment-8576643, the `PreExecutionError` field in `ActionRun` isn't well implemented as it translates the error at action runtime rather than later when the action is viewed in the UI. This PR adds an error code and error details column that can be more correctly translated. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/10267 Reviewed-by: 0ko <0ko@noreply.codeberg.org> Co-authored-by: Mathieu Fenniak <mathieu@fenniak.net> Co-committed-by: Mathieu Fenniak <mathieu@fenniak.net>
42 lines
1.5 KiB
Go
42 lines
1.5 KiB
Go
// 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)
|
|
}
|