Removed extra ERROR from wrapper errs
This commit is contained in:
@@ -47,7 +47,7 @@ func get_config(config_dir string) (*Config, error) {
|
|||||||
|
|
||||||
err := os.MkdirAll(config_dir, 0755)
|
err := os.MkdirAll(config_dir, 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &config, fmt.Errorf("ERROR: Could not create config directory: %v", err)
|
return &config, fmt.Errorf("Could not create config directory: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
config_path := filepath.Join(config_dir, "server.toml")
|
config_path := filepath.Join(config_dir, "server.toml")
|
||||||
@@ -59,19 +59,19 @@ func get_config(config_dir string) (*Config, error) {
|
|||||||
defer config_file.Close()
|
defer config_file.Close()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &config, fmt.Errorf("ERROR: Could not open config file: %v", err)
|
return &config, fmt.Errorf("Could not open config file: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fi, err := config_file.Stat()
|
fi, err := config_file.Stat()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &config, fmt.Errorf("ERROR: Could not get config file size: %v", err)
|
return &config, fmt.Errorf("Could not get config file size: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if fi.Size() == 0 {
|
if fi.Size() == 0 {
|
||||||
// if file is empty, write default config
|
// if file is empty, write default config
|
||||||
data, err := toml.Marshal(config)
|
data, err := toml.Marshal(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &config, fmt.Errorf("ERROR: Could not write default config to file: %v", err)
|
return &config, fmt.Errorf("Could not write default config to file: %v", err)
|
||||||
}
|
}
|
||||||
config_file.Write(data)
|
config_file.Write(data)
|
||||||
// return nil as the user must edit the config file
|
// return nil as the user must edit the config file
|
||||||
@@ -80,11 +80,11 @@ func get_config(config_dir string) (*Config, error) {
|
|||||||
// try to parse config file
|
// try to parse config file
|
||||||
data, err := ioutil.ReadAll(config_file)
|
data, err := ioutil.ReadAll(config_file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &config, fmt.Errorf("ERROR: Could not read data from config file: %v", err)
|
return &config, fmt.Errorf("Could not read data from config file: %v", err)
|
||||||
}
|
}
|
||||||
err = toml.Unmarshal(data, &config)
|
err = toml.Unmarshal(data, &config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &config, fmt.Errorf("ERROR: Colud not parse config file contents: %v", err)
|
return &config, fmt.Errorf("Could not parse config file contents: %v", err)
|
||||||
}
|
}
|
||||||
return &config, nil
|
return &config, nil
|
||||||
}
|
}
|
||||||
@@ -109,7 +109,7 @@ func open_database(data_dir string) (*sql.DB, error) {
|
|||||||
// create data directory
|
// create data directory
|
||||||
err := os.MkdirAll(data_dir, 0755)
|
err := os.MkdirAll(data_dir, 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("ERROR: could not create data directory: %v", err)
|
return nil, fmt.Errorf("Could not create data directory: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// open database
|
// open database
|
||||||
@@ -117,7 +117,8 @@ func open_database(data_dir string) (*sql.DB, error) {
|
|||||||
|
|
||||||
db, err := sql.Open("sqlite3", db_path)
|
db, err := sql.Open("sqlite3", db_path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("ERROR: could not open database: %v", err)
|
return nil, fmt.Errorf("Could not open database: %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return db, nil
|
return db, nil
|
||||||
@@ -134,7 +135,8 @@ type TVShow struct {
|
|||||||
func scan_directory(directory string, db *sql.DB) error {
|
func scan_directory(directory string, db *sql.DB) error {
|
||||||
files, err := ioutil.ReadDir(directory)
|
files, err := ioutil.ReadDir(directory)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
return fmt.Errorf("Could not get files in directory \"%v\": %v", directory, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
@@ -190,6 +192,7 @@ func main() {
|
|||||||
|
|
||||||
db, err := open_database(data_dir)
|
db, err := open_database(data_dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "ERROR: Could not open database: %v", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|||||||
Reference in New Issue
Block a user