aboutsummaryrefslogtreecommitdiff
path: root/lib/sql
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2021-12-16 23:01:05 +0700
committerShulhan <ms@kilabit.info>2021-12-16 23:01:05 +0700
commit5adf8d6c75a5f143f3a6da7f40b06ece699ae0d4 (patch)
tree62dd27e096271bb617c2fe14b0793c859cee5588 /lib/sql
parent320327c2bcdeb7df88a6d3c8d4f042f1c349b5f2 (diff)
downloadpakakeh.go-5adf8d6c75a5f143f3a6da7f40b06ece699ae0d4.tar.xz
lib/sql: check for EOF on loadSQL
There is probably a regression in Go that cause ioutil.ReadAll return io.EOF, while it should not, because the documentation said that A successful call returns err == nil, not err == EOF. But in this, using http.FileSystem, the ioutil.ReadAll now return EOF and we need to check it to make the migration can run without an error.
Diffstat (limited to 'lib/sql')
-rw-r--r--lib/sql/client.go9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/sql/client.go b/lib/sql/client.go
index 91bc3698..d0af4482 100644
--- a/lib/sql/client.go
+++ b/lib/sql/client.go
@@ -8,6 +8,7 @@ import (
"database/sql"
"errors"
"fmt"
+ "io"
"io/ioutil"
"log"
"net/http"
@@ -271,6 +272,8 @@ func (cl *Client) migrateFinished(tx *sql.Tx, file string) (err error) {
func loadSQL(fs http.FileSystem, fi os.FileInfo, filename string) (
sqlRaw []byte, err error,
) {
+ logp := "loadSQL"
+
if strings.ToLower(filepath.Ext(filename)) != sqlExtension {
return nil, nil
}
@@ -283,12 +286,14 @@ func loadSQL(fs http.FileSystem, fi os.FileInfo, filename string) (
file, err := fs.Open(fileSQL)
if err != nil {
- return nil, err
+ return nil, fmt.Errorf("%s: %w", logp, err)
}
sqlRaw, err = ioutil.ReadAll(file)
if err != nil {
- return nil, err
+ if !errors.Is(err, io.EOF) {
+ return nil, fmt.Errorf("%s: %w", logp, err)
+ }
}
return sqlRaw, nil