Changed the wording of error messages slightly

This commit is contained in:
David J. Allen 2024-05-08 13:39:51 -06:00
parent cc7bad8b94
commit 0403b2bcbc
No known key found for this signature in database
GPG key ID: 717C593FF60A2ACC
11 changed files with 31 additions and 32 deletions

View file

@ -21,7 +21,7 @@ func CreateProbeResultsIfNotExists(path string) (*sqlx.DB, error) {
// TODO: it may help with debugging to check for file permissions here first
db, err := sqlx.Open("sqlite3", path)
if err != nil {
return nil, fmt.Errorf("could not open database: %v", err)
return nil, fmt.Errorf("failed toopen database: %v", err)
}
db.MustExec(schema)
return db, nil
@ -45,12 +45,12 @@ func InsertProbeResults(path string, states *[]magellan.ScannedResult) error {
VALUES (:host, :port, :protocol, :state);`
_, err := tx.NamedExec(sql, &state)
if err != nil {
fmt.Printf("could not execute transaction: %v\n", err)
fmt.Printf("failed toexecute transaction: %v\n", err)
}
}
err = tx.Commit()
if err != nil {
return fmt.Errorf("could not commit transaction: %v", err)
return fmt.Errorf("failed tocommit transaction: %v", err)
}
return nil
}
@ -61,20 +61,20 @@ func DeleteProbeResults(path string, results *[]magellan.ScannedResult) error {
}
db, err := sqlx.Open("sqlite3", path)
if err != nil {
return fmt.Errorf("could not open database: %v", err)
return fmt.Errorf("failed toopen database: %v", err)
}
tx := db.MustBegin()
for _, state := range *results {
sql := `DELETE FROM magellan_scanned_ports WHERE host = :host, port = :port;`
_, err := tx.NamedExec(sql, &state)
if err != nil {
fmt.Printf("could not execute transaction: %v\n", err)
fmt.Printf("failed toexecute transaction: %v\n", err)
}
}
err = tx.Commit()
if err != nil {
return fmt.Errorf("could not commit transaction: %v", err)
return fmt.Errorf("failed tocommit transaction: %v", err)
}
return nil
}
@ -82,13 +82,13 @@ func DeleteProbeResults(path string, results *[]magellan.ScannedResult) error {
func GetProbeResults(path string) ([]magellan.ScannedResult, error) {
db, err := sqlx.Open("sqlite3", path)
if err != nil {
return nil, fmt.Errorf("could not open database: %v", err)
return nil, fmt.Errorf("failed toopen database: %v", err)
}
results := []magellan.ScannedResult{}
err = db.Select(&results, "SELECT * FROM magellan_scanned_ports ORDER BY host ASC, port ASC;")
if err != nil {
return nil, fmt.Errorf("could not retrieve probes: %v", err)
return nil, fmt.Errorf("failed toretrieve probes: %v", err)
}
return results, nil
}