Files
wanderer/db/pluginsystem/status.go
slothful-vassal 485ec53f6d feat: add plugin system (#1034)
* feat: add plugin system

* fix db docker build

* fix hammerhead readme, add strava subscription news to docs

* fixes and sdk improvements

* fix: reduce Meilisearch load, debounce federation sync (#1012)

* optimize meili trail index

* several fixes

---------

Co-authored-by: Flomp <Flomp@users.noreply.github.com>

* Bump svelte from 5.55.5 to 5.56.0 in /docs (#1032)

Bumps [svelte](https://github.com/sveltejs/svelte/tree/HEAD/packages/svelte) from 5.55.5 to 5.56.0.
- [Release notes](https://github.com/sveltejs/svelte/releases)
- [Changelog](https://github.com/sveltejs/svelte/blob/main/packages/svelte/CHANGELOG.md)
- [Commits](https://github.com/sveltejs/svelte/commits/svelte@5.56.0/packages/svelte)

---
updated-dependencies:
- dependency-name: svelte
  dependency-version: 5.56.0
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Flomp <Flomp@users.noreply.github.com>

* Release v0.19.2 (#1035)

* chore: release v0.19.2

* add changelog

---------

Co-authored-by: Flomp <26000991+Flomp@users.noreply.github.com>
Co-authored-by: Christian Beutel <>

* speed up plugin sync and several small fixes

* concepts for security improvements and process stability

* improve concept

* security concept implemented

* remove insecure TLS

* worker concept implemented

* fixes and cleanup

* fixes

* docu

* mermaid, namings

* WASM plugin host improvements, plugin logging

* fix db migration

* Improve plugin config and category mapping UI

* fixes

* further fixes

* remove manual test sync

* fix db migration and strava mapping

* type added, UI improvements

* fix plugin card toggle clickable area

* optimize synch status card layout

* plugin type 'trails' instead of 'integration'

* session auth validation in UI

* fix komoot date and waypoints

* improve category mapping

* fix send to hammerhead: trail name

* plugin setup error handling improved

* fix review findings

* re-mapping added

* rename remote_category

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Flomp <Flomp@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Flomp <26000991+Flomp@users.noreply.github.com>
2026-06-22 15:00:44 +02:00

90 lines
2.5 KiB
Go

package pluginsystem
import (
"errors"
"fmt"
"strings"
"time"
)
// PluginCapabilityError wraps a plugin-reported error returned inside a
// successful export response, so status mapping can treat it like runtime
// PluginCallError failures.
type PluginCapabilityError struct {
Err *PluginError
}
func (e PluginCapabilityError) Error() string {
if e.Err == nil {
return "plugin error"
}
if e.Err.Message == "" {
return fmt.Sprintf("plugin error %s", e.Err.Code)
}
return fmt.Sprintf("plugin error %s: %s", e.Err.Code, e.Err.Message)
}
// InstanceStatusUpdate contains the normalized status fields that are written
// back to plugin_instances after a failed sync.
type InstanceStatusUpdate struct {
Status string
Code string
Message string
RetryNotBefore *time.Time
}
// InstanceStatusForError converts sync/runtime errors into the persisted
// plugin_instances status fields used by the UI and cron backoff logic.
func InstanceStatusForError(err error, now time.Time) InstanceStatusUpdate {
var capabilityErr PluginCapabilityError
var callErr PluginCallError
if errors.As(err, &capabilityErr) && capabilityErr.Err != nil {
return InstanceStatusForPluginError(*capabilityErr.Err, now)
}
if errors.As(err, &callErr) {
return InstanceStatusForPluginError(callErr.PluginError, now)
}
return InstanceStatusUpdate{
Status: "error",
Code: "provider_unavailable",
Message: err.Error(),
}
}
// InstanceStatusForPluginError maps the stable plugin error codes from the ABI
// to host instance states. retryAfterSeconds wins over default retry windows.
func InstanceStatusForPluginError(pluginErr PluginError, now time.Time) InstanceStatusUpdate {
code := strings.TrimSpace(pluginErr.Code)
if code == "" {
code = "provider_unavailable"
}
message := strings.TrimSpace(pluginErr.Message)
if message == "" {
message = code
}
status := "error"
switch code {
case "auth_failed", "invalid_grant", "unauthorized":
status = "needs_reauth"
case "rate_limited":
status = "rate_limited"
case "provider_unavailable", "temporary_unavailable":
status = "unavailable"
}
update := InstanceStatusUpdate{
Status: status,
Code: code,
Message: message,
}
if pluginErr.RetryAfterSeconds != nil && *pluginErr.RetryAfterSeconds > 0 {
retryNotBefore := now.Add(time.Duration(*pluginErr.RetryAfterSeconds) * time.Second)
update.RetryNotBefore = &retryNotBefore
} else if code == "rate_limited" {
retryNotBefore := now.Add(time.Hour)
update.RetryNotBefore = &retryNotBefore
}
return update
}