Capitalize error messages according to staticcheck

This commit is contained in:
Gonne 2024-12-10 20:28:29 +01:00
parent e3b69e8f83
commit 30f5497aa5
7 changed files with 48 additions and 48 deletions

View file

@ -30,7 +30,7 @@ func (r *CourseRepo) FindById(id int) (models.Course, error) {
func (r *CourseRepo) GetAll() ([]models.Course, error) {
rows, err := r.db.Query("SELECT * FROM course ORDER BY name ASC")
if err != nil {
log.Printf("Error getting all courses: %s", err.Error())
log.Printf("error getting all courses: %s", err.Error())
return nil, err
}
defer rows.Close()
@ -56,9 +56,9 @@ func (r *CourseRepo) getFromRows(rows *sql.Rows) ([]models.Course, error) {
func (r *CourseRepo) getFromRow(row *sql.Row) (models.Course, error) {
var course models.Course
if err := row.Scan(&course.Id, &course.Name); err != nil {
err = fmt.Errorf("Error getting course row: %w", err)
err = fmt.Errorf("error getting course row: %w", err)
if !errors.Is(err, sql.ErrNoRows) {
log.Printf(err.Error())
log.Print(err.Error())
}
return models.Course{}, err
}

View file

@ -37,7 +37,7 @@ func (r *OfficeHourRepo) GetAll(activeOnly bool) ([]models.OfficeHour, error) {
rows, err = r.db.Query("SELECT * FROM officeHour")
}
if err != nil {
err = fmt.Errorf("Error getting all officeHours from database: %w", err)
err = fmt.Errorf("error getting all officeHours from database: %w", err)
if !errors.Is(err, sql.ErrNoRows) {
log.Println(err.Error())
}
@ -57,7 +57,7 @@ func (r *OfficeHourRepo) FindByCourse(course models.Course, activeOnly bool) ([]
}
defer rows.Close()
if err != nil {
err = fmt.Errorf("Error getting officeHours by course from database: %w", err)
err = fmt.Errorf("error getting officeHours by course from database: %w", err)
if !errors.Is(err, sql.ErrNoRows) {
log.Println(err.Error())
}
@ -75,7 +75,7 @@ func (r *OfficeHourRepo) FindByRoom(room models.Room, activeOnly bool) ([]models
rows, err = r.db.Query("SELECT * FROM officeHour WHERE room=?", room.Id)
}
if err != nil {
err = fmt.Errorf("Error getting officeHours by room from database: %w", err)
err = fmt.Errorf("error getting officeHours by room from database: %w", err)
if !errors.Is(err, sql.ErrNoRows) {
log.Println(err.Error())
}
@ -101,7 +101,7 @@ func (r *OfficeHourRepo) Add(officeHour models.OfficeHour) (int, error) {
}
officeHour.Tutor, err = r.tutorRepo.FindByNameAndEmail(officeHour.Tutor.Name, officeHour.Tutor.Email)
if err != nil {
err = fmt.Errorf("Newly added tutor not found: %w", err)
err = fmt.Errorf("newly added tutor not found: %w", err)
log.Println(err.Error())
return 0, err
}
@ -140,7 +140,7 @@ func (r *OfficeHourRepo) Add(officeHour models.OfficeHour) (int, error) {
}
id, lastInsertIdErr := sqlResult.LastInsertId()
if lastInsertIdErr != nil {
log.Printf("Error getting Id for new tutor: %s", lastInsertIdErr.Error())
log.Printf("error getting Id for new tutor: %s", lastInsertIdErr.Error())
}
return int(id), err
}
@ -148,7 +148,7 @@ func (r *OfficeHourRepo) Add(officeHour models.OfficeHour) (int, error) {
func (r *OfficeHourRepo) Delete(officeHour models.OfficeHour) error {
_, err := r.db.Exec("DELETE FROM officeHour WHERE id=?", officeHour.Id)
if err != nil {
err = fmt.Errorf("Error deleting officeHour from database: %w", err)
err = fmt.Errorf("error deleting officeHour from database: %w", err)
log.Println(err.Error())
return err
}
@ -160,26 +160,26 @@ func (r *OfficeHourRepo) getFromRow(row *sql.Row) (models.OfficeHour, error) {
var week, day, hour, minute, tutorId, courseId, roomId int
err := row.Scan(&officeHour.Id, &tutorId, &day, &hour, &minute, &roomId, &officeHour.RoomName, &courseId, &week, &officeHour.Info, &officeHour.Active, &officeHour.Duration)
if err != nil {
err = fmt.Errorf("Error getting single officeHour row from database: %w", err)
err = fmt.Errorf("error getting single officeHour row from database: %w", err)
log.Println(err.Error())
return models.OfficeHour{}, err
}
officeHour.Date = models.Date{Week: week, Day: day, Hour: hour, Minute: minute}
officeHour.Room, err = r.roomRepo.FindById(roomId)
if err != nil {
err = fmt.Errorf("Error finding room by id %d for office hour: %w", roomId, err)
err = fmt.Errorf("error finding room by id %d for office hour: %w", roomId, err)
log.Println(err.Error())
return officeHour, err
}
officeHour.Tutor, err = r.tutorRepo.FindById(tutorId)
if err != nil {
err = fmt.Errorf("Error finding tutor by id %d for office hour: %w", tutorId, err)
err = fmt.Errorf("error finding tutor by id %d for office hour: %w", tutorId, err)
log.Println(err.Error())
return officeHour, err
}
officeHour.Course, err = r.courseRepo.FindById(courseId)
if err != nil {
err = fmt.Errorf("Error finding course by id %d for office hour: %w", courseId, err)
err = fmt.Errorf("error finding course by id %d for office hour: %w", courseId, err)
log.Println(err.Error())
return officeHour, err
}
@ -193,24 +193,24 @@ func (r *OfficeHourRepo) getFromRows(rows *sql.Rows) ([]models.OfficeHour, error
var week, day, hour, minute, tutorId, roomId, courseId int
var err error
if err := rows.Scan(&officeHour.Id, &tutorId, &day, &hour, &minute, &roomId, &officeHour.RoomName, &courseId, &week, &officeHour.Info, &officeHour.Active, &officeHour.Duration); err != nil {
return officeHours, fmt.Errorf("Error getting multiple officeHour rows from database: %w", err)
return officeHours, fmt.Errorf("error getting multiple officeHour rows from database: %w", err)
}
officeHour.Date = models.Date{Week: week, Day: day, Hour: hour, Minute: minute}
officeHour.Room, err = r.roomRepo.FindById(roomId)
if err != nil {
err = fmt.Errorf("Error finding room by id %d for office hour: %w", roomId, err)
err = fmt.Errorf("error finding room by id %d for office hour: %w", roomId, err)
log.Println(err.Error())
return officeHours, err
}
officeHour.Tutor, err = r.tutorRepo.FindById(tutorId)
if err != nil {
err = fmt.Errorf("Error finding tutor by id %d for office hour: %w", tutorId, err)
err = fmt.Errorf("error finding tutor by id %d for office hour: %w", tutorId, err)
log.Println(err.Error())
return officeHours, err
}
officeHour.Course, err = r.courseRepo.FindById(courseId)
if err != nil {
err = fmt.Errorf("Error finding course by id %d for office hour: %w", courseId, err)
err = fmt.Errorf("error finding course by id %d for office hour: %w", courseId, err)
log.Println(err.Error())
return officeHours, err
}
@ -229,7 +229,7 @@ func (r *OfficeHourRepo) NumberByTimeSpanAndRoom(date models.Date, duration int,
rows, err = r.db.Query("SELECT * FROM officeHour WHERE room=?", room.Id)
}
if err != nil {
err = fmt.Errorf("Error getting officeHours by timespan and room from database: %w", err)
err = fmt.Errorf("error getting officeHours by timespan and room from database: %w", err)
log.Println(err.Error())
return 0, err
}

View file

@ -55,7 +55,7 @@ func (r *RequestRepo) FindByOfficeHour(officeHour models.OfficeHour) ([]models.R
var request models.Request
var officeHourId int
if err := rows.Scan(&request.Id, &officeHourId, &request.Action, &request.Secret); err != nil {
err = fmt.Errorf("Error scanning request row: %w", err)
err = fmt.Errorf("error scanning request row: %w", err)
log.Println(err.Error())
return requests, err
}
@ -110,7 +110,7 @@ func (r *RequestRepo) Execute(request models.Request) error {
r.db.Exec("DELETE FROM request WHERE officeHour=?", request.OfficeHour.Id)
err = r.officeHourRepo.Delete(request.OfficeHour)
default:
log.Printf("Executing request: Action type %d unknown.", request.Action)
log.Printf("executing request: Action type %d unknown.", request.Action)
_, err = r.db.Exec("DELETE FROM request WHERE id=?", request.Id)
}
return err
@ -140,7 +140,7 @@ func (r *RequestRepo) sendConfirmationMail(request models.Request) error {
}{r.config, request, template.HTML("<" + randomString(15) + "@" + r.config.Server.Domain + ">")}
err := templating.WriteTemplate(&message, "confirmationMail", data)
if err != nil {
err = fmt.Errorf("Error parsing confirmation Mail: %w", err)
err = fmt.Errorf("error parsing confirmation Mail: %w", err)
log.Println(err.Error())
return err
}
@ -156,7 +156,7 @@ func (r *RequestRepo) sendConfirmationMail(request models.Request) error {
}
err = smtp.SendMail(fmt.Sprintf("%s:%d", r.config.Mailer.SmtpHost, r.config.Mailer.SmtpPort), auth, string(r.config.Mailer.FromName), to, message.Bytes())
if err != nil {
err = fmt.Errorf("Error sending mail by smtp: %w", err)
err = fmt.Errorf("error sending mail by smtp: %w", err)
log.Println(err.Error())
}
return err

View file

@ -31,7 +31,7 @@ func (r *RoomRepo) FindById(id int) (models.Room, error) {
row := r.db.QueryRow("SELECT * FROM room WHERE id=?", id)
var room models.Room
if err := row.Scan(&room.Id, &room.Name, &room.MaxOccupy); err != nil {
err = fmt.Errorf("Error scanning row to get room: %w", err)
err = fmt.Errorf("error scanning row to get room: %w", err)
if !errors.Is(err, sql.ErrNoRows) {
log.Println(err.Error())
}
@ -43,7 +43,7 @@ func (r *RoomRepo) FindById(id int) (models.Room, error) {
func (r *RoomRepo) GetAll() ([]models.Room, error) {
rows, err := r.db.Query("SELECT * FROM room ORDER BY name ASC")
if err != nil {
err = fmt.Errorf("Error getting all rooms: %w", err)
err = fmt.Errorf("error getting all rooms: %w", err)
log.Println(err.Error())
return nil, err
}
@ -53,7 +53,7 @@ func (r *RoomRepo) GetAll() ([]models.Room, error) {
for rows.Next() {
var room models.Room
if err := rows.Scan(&room.Id, &room.Name, &room.MaxOccupy); err != nil {
err = fmt.Errorf("Error scanning row to get room: %w", err)
err = fmt.Errorf("error scanning row to get room: %w", err)
return rooms, err
}
rooms = append(rooms, room)

View file

@ -58,7 +58,7 @@ func (r *TutorRepo) Add(tutor models.Tutor) (int, error) {
}
id, lastInsertIdErr := sqlResult.LastInsertId()
if lastInsertIdErr != nil {
log.Printf("Error getting Id for new tutor: %s", lastInsertIdErr.Error())
log.Printf("error getting Id for new tutor: %s", lastInsertIdErr.Error())
}
return int(id), err
}
@ -80,7 +80,7 @@ func (r *TutorRepo) getFromRows(rows *sql.Rows) ([]models.Tutor, error) {
for rows.Next() {
var tutor models.Tutor
if err := rows.Scan(&tutor.Id, &tutor.Name, &tutor.Email, &tutor.SubscribeToMailinglist); err != nil {
err = fmt.Errorf("Error scanning tutor row: %w", err)
err = fmt.Errorf("error scanning tutor row: %w", err)
log.Println(err.Error())
return tutors, err
}