Browse Source

Errors: Add PrintRemovedFeatureError & PrintDeprecatedFeatureWarning (#3804)

pull/3818/head
Kobe Arthur Scofield 2 months ago committed by GitHub
parent
commit
5f0642a671
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 3
      app/dns/dns.go
  2. 3
      app/dns/hosts.go
  3. 25
      common/errors/feature_errors.go
  4. 15
      features/feature.go
  5. 2
      infra/conf/transport_internet.go
  6. 4
      infra/conf/trojan.go
  7. 2
      infra/conf/xray.go
  8. 3
      proxy/socks/server.go

3
app/dns/dns.go

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

3
app/dns/hosts.go

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

25
common/errors/feature_errors.go

@ -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.")
}
}

15
features/feature.go

@ -1,27 +1,12 @@
package features package features
import ( import (
"context"
"github.com/xtls/xray-core/common" "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. // 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. // All existing features have an implementation in app directory. These features can be replaced by third-party ones.
type Feature interface { type Feature interface {
common.HasType common.HasType
common.Runnable 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.")
}

2
infra/conf/transport_internet.go

@ -813,7 +813,7 @@ func (c *StreamConfig) Build() (*internet.StreamConfig, error) {
config.SecuritySettings = append(config.SecuritySettings, tm) config.SecuritySettings = append(config.SecuritySettings, tm)
config.SecurityType = tm.Type config.SecurityType = tm.Type
case "xtls": 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: default:
return nil, errors.New(`Unknown security "` + c.Security + `".`) return nil, errors.New(`Unknown security "` + c.Security + `".`)
} }

4
infra/conf/trojan.go

@ -52,7 +52,7 @@ func (c *TrojanClientConfig) Build() (proto.Message, error) {
return nil, errors.New("Trojan password is not specified.") return nil, errors.New("Trojan password is not specified.")
} }
if rec.Flow != "" { 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{ config.Server[idx] = &protocol.ServerEndpoint{
@ -106,7 +106,7 @@ func (c *TrojanServerConfig) Build() (proto.Message, error) {
for idx, rawUser := range c.Clients { for idx, rawUser := range c.Clients {
if rawUser.Flow != "" { 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{ config.Users[idx] = &protocol.User{

2
infra/conf/xray.go

@ -593,7 +593,7 @@ func (c *Config) Build() (*core.Config, error) {
} }
if len(c.Transport) > 0 { 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 { for _, rawInboundConfig := range inbounds {

3
proxy/socks/server.go

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

Loading…
Cancel
Save