Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors: Add PrintRemovedFeatureError & PrintDeprecatedFeatureWarning #3804

Merged
merged 8 commits into from
Sep 15, 2024
Merged
3 changes: 1 addition & 2 deletions app/dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions app/dns/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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)
Expand Down
25 changes: 25 additions & 0 deletions common/errors/feature_errors.go
Original file line number Diff line number Diff line change
@@ -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 changes: 0 additions & 15 deletions features/feature.go
Original file line number Diff line number Diff line change
@@ -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.")
}
2 changes: 1 addition & 1 deletion infra/conf/transport_internet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 + `".`)
}
Expand Down
4 changes: 2 additions & 2 deletions infra/conf/trojan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion infra/conf/xray.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions proxy/socks/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
Loading