Redis 连不上时别把库写给开发者的建议摆给用户 - #22
Merged
Merged
Conversation
StackExchange.Redis 在连不上时会在异常消息尾巴上附一句 "…use abortConnect=false in your connection string or AbortOnConnectFail=false; in your code"。 这句话经 ProtocolConnectionException 一路走到宿主的连接失败提示框里,有两重坏处: 用户根本没有"连接字符串"可改,而那恰恰是本插件**刻意不采纳**的做法 —— 设 false 会让 ConnectAsync 成功返回一个后台重试中的对象,界面于是画出一个空键树、 然后每个操作各自超时。所以在出口处剪掉。 补两条纪律进 README:首次连接必须大声失败(AbortOnConnectFail = true), 以及这一条"不把库写给开发者的建议摆给用户"。 新增 RedisWorkspaceProviderTests:死端口必抛 ProtocolConnectionException、 消息里要带端点、且不含 abortConnect —— 宿主不会为一条连不上的连接开标签页, 不抛就等于什么都没发生。 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J5gfiQ8G3JfqomjRkuHmPP
13 tasks
2 tasks
13 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
这个 PR 做了什么
连不上时,把 StackExchange.Redis 附在异常消息尾巴上那句写给开发者的建议剪掉,再抛给宿主。
为什么这么改
用户报"本机没起 Redis,点开一条
127.0.0.1:6379的会话,没有任何提示"。排查下来插件这边是对的 ——RedisWorkspaceProvider.OpenAsync老老实实抛了ProtocolConnectionException,静默的原因在宿主(见下面的关联 PR)。但宿主把提示框补上之后,这条消息就要摆到用户眼前了,而它现在长这样:
后面那句有两重坏处:
AbortOnConnectFail = true是有理由的(见RedisConnection.ConnectAsync的注释):设 false 会让ConnectAsync成功返回一个后台重试中的对象,界面于是画出一个空的键树,然后每个操作各自超时 —— 那是最难排查的一种坏。把这句照搬给用户,等于在提示框里教他去要那个结果。所以在
Describe这个出口处剪掉。剩下的It was not possible to connect to the redis server(s). Error connecting right now.仍然是有用的信息。改动
RedisWorkspaceProvider.Describe:遇到To allow this multiplexer就截断。AbortOnConnectFail = true,以及"宿主不会为一条连不上的连接开标签页,不抛就等于什么都没发生"),不把库写给开发者的建议摆给用户。怎么验证的
dotnet build VelaShell.Plugins.slnx—— 零警告零错误dotnet test VelaShell.Plugins.slnx—— 全绿(跳过的 84 例是需要本机真有 Redis 的集成用例,按仓库惯例报 Inconclusive。)
新增
RedisWorkspaceProviderTests(2 例),打一个几乎肯定没人监听的高位端口63799(不用 6379:开发机上它常常是通的,那样用例会在有 Redis 的机器上悄悄失去意义):OpenAsync_WhenNothingIsListening_ThrowsAProtocolConnectionExceptionOpenAsync_StripsTheLibrarysAbortConnectAdviceabortConnect/AbortOnConnectFail补充说明
这个 PR 单独合上去也是对的(消息变干净了),但用户看得见提示框,要等宿主那条一起。
关联 PR(一起合)