llm,readline: use errors.Is instead of simple == check (#3161)

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 <jmorganca@gmail.com>
This commit is contained in:
Blake Mizerany 2024-03-15 07:14:12 -07:00 committed by GitHub
parent 703684a82a
commit 6ce37e4d96
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 4 additions and 3 deletions

View file

@ -3,6 +3,7 @@ package llm
import ( import (
"bytes" "bytes"
"encoding/binary" "encoding/binary"
"errors"
"fmt" "fmt"
"io" "io"
"log/slog" "log/slog"
@ -540,7 +541,7 @@ func (llm *GGUFModel) Encode(f *os.File) error {
b, err := io.ReadFull(dataFile, data) b, err := io.ReadFull(dataFile, data)
remaining -= uint64(b) remaining -= uint64(b)
if err == io.EOF || remaining <= 0 { if errors.Is(err, io.EOF) || remaining <= 0 {
finished = true finished = true
} else if err != nil { } else if err != nil {
return err return err

View file

@ -113,7 +113,7 @@ func nativeInit() error {
libs, err := extractDynamicLibs(payloadsDir, "llama.cpp/build/*/*/*/lib/*") libs, err := extractDynamicLibs(payloadsDir, "llama.cpp/build/*/*/*/lib/*")
if err != nil { if err != nil {
if err == payloadMissing { if errors.Is(err, payloadMissing) {
slog.Info(fmt.Sprintf("%s", payloadMissing)) slog.Info(fmt.Sprintf("%s", payloadMissing))
return nil return nil
} }

View file

@ -62,7 +62,7 @@ func (h *History) Init() error {
for { for {
line, err := r.ReadString('\n') line, err := r.ReadString('\n')
if err != nil { if err != nil {
if err == io.EOF { if errors.Is(err, io.EOF) {
break break
} }
return err return err