Errors: Add PrintRemovedFeatureError & PrintDeprecatedFeatureWarning (#3804)

This commit is contained in:
Kobe Arthur Scofield 2024-09-15 12:55:54 +08:00 committed by GitHub
parent 3fed0c773f
commit 5f0642a671
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 32 additions and 25 deletions

View file

@ -15,7 +15,6 @@ import (
"github.com/xtls/xray-core/common/net"
"github.com/xtls/xray-core/common/session"
"github.com/xtls/xray-core/common/strmatcher"
"github.com/xtls/xray-core/features"
"github.com/xtls/xray-core/features/dns"
)
@ -96,7 +95,7 @@ func New(ctx context.Context, config *Config) (*DNS, error) {
geoipContainer := router.GeoIPMatcherContainer{}
for _, endpoint := range config.NameServers {
features.PrintDeprecatedFeatureWarning("simple DNS server")
errors.PrintDeprecatedFeatureWarning("simple DNS server", "")
client, err := NewSimpleClient(ctx, endpoint, clientIP)
if err != nil {
return nil, errors.New("failed to create client").Base(err)

View file

@ -7,7 +7,6 @@ import (
"github.com/xtls/xray-core/common/errors"
"github.com/xtls/xray-core/common/net"
"github.com/xtls/xray-core/common/strmatcher"
"github.com/xtls/xray-core/features"
"github.com/xtls/xray-core/features/dns"
)
@ -26,7 +25,7 @@ func NewStaticHosts(hosts []*Config_HostMapping, legacy map[string]*net.IPOrDoma
}
if legacy != nil {
features.PrintDeprecatedFeatureWarning("simple host mapping")
errors.PrintDeprecatedFeatureWarning("simple host mapping", "")
for domain, ip := range legacy {
matcher, err := strmatcher.Full.New(domain)

View file

@ -0,0 +1,25 @@
package errors
import (
"context"
)
// PrintDeprecatedFeatureWarning prints a warning for deprecated and going to be removed feature.
// Do not remove this function even there is no reference to it.
func PrintDeprecatedFeatureWarning(feature string, migrateFeature string) {
if len(migrateFeature) > 0 {
LogWarning(context.Background(), "This feature " + feature + " is deprecated and being migrated to " + migrateFeature + ". Please update your config(s) according to release note and documentation before removal.")
} else {
LogWarning(context.Background(), "This feature " + feature + " is deprecated. Please update your config(s) according to release note and documentation before removal.")
}
}
// PrintRemovedFeatureError prints an error message for removed feature then return an error. And after long enough time the message can also be removed, uses as an indicator.
// Do not remove this function even there is no reference to it.
func PrintRemovedFeatureError(feature string, migrateFeature string) (error) {
if len(migrateFeature) > 0 {
return New("The feature " + feature + " has been removed and migrated to " + migrateFeature + ". Please update your config(s) according to release note and documentation.")
} else {
return New("The feature " + feature + " has been removed. Please update your config(s) according to release note and documentation.")
}
}

View file

@ -1,27 +1,12 @@
package features
import (
"context"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/errors"
)
//go:generate go run github.com/xtls/xray-core/common/errors/errorgen
// Feature is the interface for Xray features. All features must implement this interface.
// All existing features have an implementation in app directory. These features can be replaced by third-party ones.
type Feature interface {
common.HasType
common.Runnable
}
// PrintDeprecatedFeatureWarning prints a warning for deprecated feature.
func PrintDeprecatedFeatureWarning(feature string) {
errors.LogWarning(context.Background(), "You are using a deprecated feature: " + feature + ". Please update your config file(s) with latest configuration format, or update your client software.")
}
// PrintRemovedFeatureError prints an error message for removed feature. And after long enough time the message can also be removed, use as an indicator.
func PrintRemovedFeatureError(feature string) {
errors.New("The feature " + feature + " is removed. Please update your config file(s) according to release notes and documentations.")
}

View file

@ -813,7 +813,7 @@ func (c *StreamConfig) Build() (*internet.StreamConfig, error) {
config.SecuritySettings = append(config.SecuritySettings, tm)
config.SecurityType = tm.Type
case "xtls":
return nil, errors.New(`Please use VLESS flow "xtls-rprx-vision" with TLS or REALITY.`)
return nil, errors.PrintRemovedFeatureError(`Legacy XTLS`, `xtls-rprx-vision with TLS or REALITY`)
default:
return nil, errors.New(`Unknown security "` + c.Security + `".`)
}

View file

@ -52,7 +52,7 @@ func (c *TrojanClientConfig) Build() (proto.Message, error) {
return nil, errors.New("Trojan password is not specified.")
}
if rec.Flow != "" {
return nil, errors.New(`Trojan doesn't support "flow" anymore.`)
return nil, errors.PrintRemovedFeatureError(`Flow for Trojan`, ``)
}
config.Server[idx] = &protocol.ServerEndpoint{
@ -106,7 +106,7 @@ func (c *TrojanServerConfig) Build() (proto.Message, error) {
for idx, rawUser := range c.Clients {
if rawUser.Flow != "" {
return nil, errors.New(`Trojan doesn't support "flow" anymore.`)
return nil, errors.PrintRemovedFeatureError(`Flow for Trojan`, ``)
}
config.Users[idx] = &protocol.User{

View file

@ -593,7 +593,7 @@ func (c *Config) Build() (*core.Config, error) {
}
if len(c.Transport) > 0 {
return nil, errors.New("Global transport config is deprecated")
return nil, errors.PrintRemovedFeatureError("Global transport config", "streamSettings in inbounds and outbounds")
}
for _, rawInboundConfig := range inbounds {

View file

@ -16,7 +16,6 @@ import (
"github.com/xtls/xray-core/common/signal"
"github.com/xtls/xray-core/common/task"
"github.com/xtls/xray-core/core"
"github.com/xtls/xray-core/features"
"github.com/xtls/xray-core/features/policy"
"github.com/xtls/xray-core/features/routing"
"github.com/xtls/xray-core/proxy/http"
@ -56,7 +55,7 @@ func (s *Server) policy() policy.Session {
config := s.config
p := s.policyManager.ForLevel(config.UserLevel)
if config.Timeout > 0 {
features.PrintDeprecatedFeatureWarning("Socks timeout")
errors.PrintDeprecatedFeatureWarning("Socks timeout", "Policy level")
}
if config.Timeout > 0 && config.UserLevel == 0 {
p.Timeouts.ConnectionIdle = time.Duration(config.Timeout) * time.Second