Skip to content

Typed error for NOSCRIPT replies from Redis#3738

Merged
ndyakov merged 1 commit into
redis:masterfrom
LINKIWI:noscript-typed-error
Mar 18, 2026
Merged

Typed error for NOSCRIPT replies from Redis#3738
ndyakov merged 1 commit into
redis:masterfrom
LINKIWI:noscript-typed-error

Conversation

@LINKIWI

@LINKIWI LINKIWI commented Mar 16, 2026

Copy link
Copy Markdown
Contributor

This PR proposes exposing a typed error ErrNoScript that indicates a NOSCRIPT reply from Redis during script execution.

This allows library consumers who directly use the EvalSha API (as opposed to the *redis.Script abstraction) to explicitly detect and handle this case, without needing to roll their own error introspection logic:

ctx := ...
rdb := redis.NewClient(...)

r, err := rdb.EvalSha(ctx, sha1, []string{...}).Result()
if errors.Is(err, redis.ErrNoScript) {
    ...
}

...

This change also makes the internal implementation of *redis.Script less fragile, in that the EvalSha and EvalShaRO callsites can check for a typed error rather than performing error string prefix matching.

I have added two new unit tests to exercise the behavior.


Note

Medium Risk
Changes the error value returned from EvalSha/EvalShaRO when Redis replies NOSCRIPT, which could affect consumers that compare error strings or types. Scope is limited to scripting command error handling plus new tests.

Overview
Adds a new exported typed error redis.ErrNoScript to represent Redis NOSCRIPT replies for missing script digests.

Updates the scripting command path so EvalSha/EvalShaRO normalize NOSCRIPT responses to ErrNoScript, and updates (*Script).Run/RunRO to use errors.Is against this typed error instead of string-prefix matching. Adds unit tests asserting NOSCRIPT is propagated as redis.ErrNoScript for unknown digests.

Written by Cursor Bugbot for commit 27fd86f. This will update automatically on new commits. Configure here.

Comment thread error.go

@ndyakov ndyakov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @LINKIWI, this looks good!

@ndyakov ndyakov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@ndyakov ndyakov merged commit 2ba8388 into redis:master Mar 18, 2026
56 of 57 checks passed
@LINKIWI LINKIWI deleted the noscript-typed-error branch March 18, 2026 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants