Files
team/server/channels/app/property_errors.go
zeekay 8feb24ea1f One name for this fork, and it is ours
The server module named github.com/hanzoai/team/server/v8 — a path that
resolves to the retired workspace's repository, not this one — while
server/public still published github.com/mattermost/mattermost/server/public.
Both are github.com/hanzoteam/server/... now, which is where this code
actually lives.

That second half is what made the binary unbootable. Upstream's public path
stayed claimed by upstream, mattermost-plugin-ai imported it, and the build
linked public/model twice; public/plugin's gob.Register then ran twice under
one name and panicked at init, before main. Reverting the rename traded the
brand for a working binary. Rebranding the plugin alongside it needs no such
trade: the agents fork is github.com/hanzoteam/agents/v2 against our public
module, so no module named mattermost/mattermost is in the graph at all.

Measured: `go list -deps ./cmd/mattermost` names exactly one public/model, and
it is ours.
2026-08-28 23:35:36 -07:00

78 lines
3.7 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
import (
"errors"
"net/http"
"github.com/hanzoteam/server/server/public/model"
"github.com/hanzoteam/server/server/v8/channels/app/properties"
"github.com/hanzoteam/server/server/v8/channels/store"
)
// mapPropertyServiceError translates known errors from the property service /
// PropertyHook chain — package sentinels (properties.Err*) and store-layer
// errors (*store.ErrNotFound, *store.ErrConflict, *store.ErrResultsMismatch) —
// into HTTP-shaped AppErrors. Returns nil if err is not recognised and does
// not wrap an AppError; callers should fall back to wrapping with their own
// default 500 in that case.
//
// Sentinel matches take priority over a wrapped AppError so that hook code
// wrapping an inner AppError with a sentinel still drives the mapping.
//
// User-facing DetailedError is left empty on access-control rejections to
// avoid leaking field IDs, plugin IDs, and sync source names. The full
// chain remains available for operator logs via Wrap(err).
func mapPropertyServiceError(where string, err error) *model.AppError {
if err == nil {
return nil
}
switch {
case errors.Is(err, properties.ErrAccessDenied):
return model.NewAppError(where, "app.property.access_denied.app_error", nil, "", http.StatusForbidden).Wrap(err)
case errors.Is(err, properties.ErrSyncLocked):
return model.NewAppError(where, "app.property.sync_lock.app_error", nil, "", http.StatusForbidden).Wrap(err)
case errors.Is(err, properties.ErrInvalidAccessMode):
return model.NewAppError(where, "app.property.invalid_access_mode.app_error", nil, err.Error(), http.StatusBadRequest).Wrap(err)
case errors.Is(err, properties.ErrFieldLimitReached):
return model.NewAppError(where, "app.property_field.create.limit_reached.app_error", nil, err.Error(), http.StatusUnprocessableEntity).Wrap(err)
case errors.Is(err, properties.ErrGroupFieldLimitReached):
return model.NewAppError(where, "app.property_field.create.group_limit_reached.app_error", nil, err.Error(), http.StatusUnprocessableEntity).Wrap(err)
case errors.Is(err, properties.ErrLicenseRequired):
return model.NewAppError(where, "app.property.license_error", nil, "", http.StatusForbidden).Wrap(err)
case errors.Is(err, properties.ErrInvalidFieldAttrs):
return model.NewAppError(where, "app.property_field.invalid_attrs.app_error", nil, err.Error(), http.StatusBadRequest).Wrap(err)
case errors.Is(err, properties.ErrInvalidValue):
return model.NewAppError(where, "app.property_value.validate.app_error", nil, err.Error(), http.StatusBadRequest).Wrap(err)
case errors.Is(err, properties.ErrAdminRequired):
return model.NewAppError(where, "app.property_field.managed_admin.permission.app_error", nil, "", http.StatusForbidden).Wrap(err)
case errors.Is(err, properties.ErrFieldNotFound):
return model.NewAppError(where, "app.property_field.not_found.app_error", nil, "", http.StatusNotFound).Wrap(err)
}
var conflictErr *store.ErrConflict
if errors.As(err, &conflictErr) {
return model.NewAppError(where, "app.property_field.update.conflict.app_error", nil, "concurrent modification detected; please retry", http.StatusConflict).Wrap(err)
}
var notFoundErr *store.ErrNotFound
if errors.As(err, &notFoundErr) {
return model.NewAppError(where, "app.property.not_found.app_error", nil, "", http.StatusNotFound).Wrap(err)
}
var resultsMismatchErr *store.ErrResultsMismatch
if errors.As(err, &resultsMismatchErr) {
return model.NewAppError(where, "app.property.not_found.app_error", nil, "", http.StatusNotFound).Wrap(err)
}
var appErr *model.AppError
if errors.As(err, &appErr) {
return appErr
}
return nil
}