Skip to content

Commit

Permalink
llm,readline: use errors.Is instead of simple == check (ollama#3161)
Browse files Browse the repository at this point in the history
This fixes some brittle, simple equality checks to use errors.Is. Since
go1.13, errors.Is is the idiomatic way to check for errors.

Co-authored-by: Jeffrey Morgan <[email protected]>
  • Loading branch information
bmizerany and jmorganca authored Mar 15, 2024
1 parent 703684a commit 6ce37e4
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion llm/gguf.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package llm
import (
"bytes"
"encoding/binary"
"errors"
"fmt"
"io"
"log/slog"
Expand Down Expand Up @@ -540,7 +541,7 @@ func (llm *GGUFModel) Encode(f *os.File) error {
b, err := io.ReadFull(dataFile, data)
remaining -= uint64(b)

if err == io.EOF || remaining <= 0 {
if errors.Is(err, io.EOF) || remaining <= 0 {
finished = true
} else if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion llm/payload_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func nativeInit() error {

libs, err := extractDynamicLibs(payloadsDir, "llama.cpp/build/*/*/*/lib/*")
if err != nil {
if err == payloadMissing {
if errors.Is(err, payloadMissing) {
slog.Info(fmt.Sprintf("%s", payloadMissing))
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion readline/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (h *History) Init() error {
for {
line, err := r.ReadString('\n')
if err != nil {
if err == io.EOF {
if errors.Is(err, io.EOF) {
break
}
return err
Expand Down

0 comments on commit 6ce37e4

Please sign in to comment.