Skip to content

The compiler now rejects constant format strings containing %w #5

@olekukonko

Description

@olekukonko

errors: allow Newf("%w",…) to compile under Go 1.20+ vet

The compiler now rejects constant format strings containing %w unless
the matching argument has static type error. We want to keep the
convenient call-sites:

return errors.Newf("extracting fields: %w", err)

if err is not statically error.

while still supporting %w at run-time. Make the format parameter
interface{} so the vet check is skipped, then immediately assert it
back to string (or fmt.Stringer) inside the function. No exported API
or behaviour changes; only the signature of Newf is widened to:

func Newf(format interface{}, args ...interface{}) *Error

All existing code continues to compile and work exactly as before.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions