Skip to content

fix: replace deprecated library usage patterns#2798

Open
bfirsh wants to merge 4 commits intomainfrom
fix/deprecated-library-usage
Open

fix: replace deprecated library usage patterns#2798
bfirsh wants to merge 4 commits intomainfrom
fix/deprecated-library-usage

Conversation

@bfirsh
Copy link
Member

@bfirsh bfirsh commented Mar 3, 2026

Summary

  • Replace deprecated github.com/pkg/errors with fmt.Errorf in pkg/docker/build_secrets.go
  • Replace os.IsNotExist() with errors.Is(err, os.ErrNotExist) across 6 call sites — os.IsNotExist doesn't unwrap error chains
  • Replace direct err == sentinel comparison with errors.Is() for ErrMissingDeviceDriver in 3 files, matching the pattern already used in pkg/cli/predict.go
  • Replace http.Get()/http.PostForm() with http.NewRequestWithContext() + client.Do() — the convenience functions create requests without a context, making them impossible to cancel

Each fix is in a separate commit for easy review.

bfirsh added 3 commits March 3, 2026 14:52
The pkg/errors package is deprecated. Replace errors.Errorf() calls in
pkg/docker/build_secrets.go with fmt.Errorf(), which is a direct drop-in
since no error wrapping with %w was used. This removes the direct
dependency on pkg/errors (it remains as an indirect dep of other packages).
os.IsNotExist() does not unwrap error chains, which means it can miss
wrapped os.ErrNotExist errors. errors.Is() correctly traverses the error
chain and is the recommended approach since Go 1.13.

Affected files:
- pkg/image/build.go (2 occurrences)
- pkg/cli/predict.go
- pkg/config/validate.go
- pkg/model/weight_builder.go
- pkg/util/files/files.go
…eviceDriver

Direct err == sentinel comparison does not unwrap error chains. Use
errors.Is() for consistent and correct sentinel error checking, matching
the pattern already used in pkg/cli/predict.go.

Affected files:
- pkg/cli/run.go
- pkg/cli/serve.go
- pkg/image/openapi_schema.go
@bfirsh bfirsh requested a review from a team as a code owner March 3, 2026 21:50
http.Get() and http.PostForm() create requests without a context, making
them impossible to cancel and susceptible to hanging indefinitely. Use
http.NewRequestWithContext() + client.Do() instead.

- pkg/predict/predictor.go: GetSchema() now uses context.Background()
- pkg/provider/replicate/replicate.go: getDisplayTokenURL() and
  verifyToken() now accept and propagate context from their callers
@bfirsh bfirsh force-pushed the fix/deprecated-library-usage branch from b76390f to 6e57523 Compare March 3, 2026 22:38
@michaeldwan michaeldwan added this to the 0.18.0 milestone Mar 5, 2026
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.

2 participants