Skip to content

Commit 4015bc6

Browse files
committed
remove rill specific error messages
1 parent 6e5c01f commit 4015bc6

File tree

2 files changed

+10
-30
lines changed

2 files changed

+10
-30
lines changed

db.go

+7-19
Original file line numberDiff line numberDiff line change
@@ -276,16 +276,6 @@ func NewDB(ctx context.Context, dbIdentifier string, opts *DBOptions) (DB, error
276276
// create read handle
277277
db.readHandle, err = db.openDBAndAttach(ctx, true)
278278
if err != nil {
279-
// Check for using incompatible database files
280-
if strings.Contains(err.Error(), "Trying to read a database file with version number") {
281-
return nil, fmt.Errorf("database file was created with an older, incompatible version of Rill (please remove `tmp` directory and try again)")
282-
}
283-
284-
// Check for another process currently accessing the DB
285-
if strings.Contains(err.Error(), "Could not set lock on file") {
286-
return nil, fmt.Errorf("failed to open database (is Rill already running?): %w", err)
287-
}
288-
289279
if strings.Contains(err.Error(), "Symbol not found") {
290280
fmt.Printf("Your version of macOS is not supported. Please upgrade to the latest major release of macOS. See this link for details: https://support.apple.com/en-in/macos/upgrade")
291281
os.Exit(1)
@@ -990,14 +980,12 @@ func (d *db) attachDBs(ctx context.Context, db *sqlx.DB, path string, read bool)
990980
if !entry.IsDir() {
991981
continue
992982
}
993-
version, exist, err := tableVersion(path, entry.Name())
994-
if err != nil {
995-
d.logger.Debug("error in fetching db version", slog.String("table", entry.Name()), slog.Any("error", err))
996-
_ = os.RemoveAll(filepath.Join(path, entry.Name()))
997-
continue
998-
}
983+
984+
// NOTE :: we always look at the write version
985+
// Tables in read path are removed after getting a new handle
986+
// So we need to always look at the write version to ensure we do not reattach dropped tables
987+
version, exist, _ := d.writeTableVersion(entry.Name())
999988
if !exist {
1000-
_ = os.RemoveAll(filepath.Join(path, entry.Name()))
1001989
continue
1002990
}
1003991
versionPath := filepath.Join(path, entry.Name(), version)
@@ -1031,8 +1019,8 @@ func (d *db) attachDBs(ctx context.Context, db *sqlx.DB, path string, read bool)
10311019
}
10321020
_, err := db.ExecContext(ctx, fmt.Sprintf("ATTACH %s AS %s %s", safeSQLString(filepath.Join(versionPath, "data.db")), safeSQLName(dbName), readMode))
10331021
if err != nil {
1034-
d.logger.Warn("error in attaching db", slog.String("table", entry.Name()), slog.Any("error", err))
1035-
_ = os.RemoveAll(versionPath)
1022+
d.logger.Error("error in attaching db", slog.String("table", entry.Name()), slog.Any("error", err))
1023+
_ = os.RemoveAll(filepath.Join(path, entry.Name()))
10361024
return err
10371025
}
10381026

singledb.go

+3-11
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,10 @@ func NewSingleDB(ctx context.Context, opts *SingleDBOptions) (DB, error) {
6363
return nil
6464
})
6565
if err != nil {
66-
// Check for using incompatible database files
67-
if strings.Contains(err.Error(), "Trying to read a database file with version number") {
68-
return nil, err
69-
// TODO :: fix
70-
// return nil, fmt.Errorf("database file %q was created with an older, incompatible version of Rill (please remove it and try again)", c.config.DSN)
71-
}
72-
73-
// Check for another process currently accessing the DB
74-
if strings.Contains(err.Error(), "Could not set lock on file") {
75-
return nil, fmt.Errorf("failed to open database (is Rill already running?): %w", err)
66+
if strings.Contains(err.Error(), "Symbol not found") {
67+
fmt.Printf("Your version of macOS is not supported. Please upgrade to the latest major release of macOS. See this link for details: https://support.apple.com/en-in/macos/upgrade")
68+
os.Exit(1)
7669
}
77-
7870
return nil, err
7971
}
8072

0 commit comments

Comments
 (0)