Skip to content

fix: use stderrors AsType and bump to Go 1.26 - #66

Open
kian99 wants to merge 1 commit into
juju:v1from
kian99:fix-as-type
Open

kian99 wants to merge 1 commit into
juju:v1from
kian99:fix-as-type

Conversation

@kian99

@kian99 kian99 commented Oct 22, 2026

Copy link
Copy Markdown

The Juju errors package introduced a generic AsType function before it was introduced in Go 1.26. Our implementation didn't cater for multiple wrapped errors e.g. the following test fails,

func TestAsTypeMultipleWrappedErrors(t *testing.T) {
    target := &fs.PathError{Op: "open", Path: "/missing", Err: fs.ErrNotExist}
    err := fmt.Errorf("%w: %w", io.EOF, target)

    got, ok := errors.AsType[*fs.PathError](err)
    if !ok || got != target {
        t.Fatalf("AsType() = (%v, %v), want (%v, true)", got, ok, target)
    }
}

This change updates the go.mod to 1.26 and switches to the stdlib AsType implementation.

Note: I'm not sure which branch this should land in v1/v2/master. Juju currently uses the v1 branch so I've opted for that but master is a few commits ahead.

@ale8k
ale8k requested a balanced review from Copilot October 22, 2026 13:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The replacement tests need a multiple-wrapped-error regression case to protect the intended fix.

1 open issue
What changed in this PR

This PR delegates Juju’s generic AsType helper to the Go standard library to support error trees containing multiple wrapped errors.

Changes:

  • Raises the minimum Go version from 1.18 to 1.26.
  • Replaces custom AsType traversal with stderrors.AsType.
  • Replaces the previous generic-helper tests with Juju wrapper cases.
File Description
go.mod Requires Go 1.26 for standard-library AsType.
functions.go Delegates AsType to the standard library and simplifies its documentation.
functions_test.go Replaces existing AsType and HasType coverage with wrapper-focused tests.

Review effort: Balanced

Comment thread functions_test.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants