Chore: linter complaints

This commit is contained in:
Grail Finder
2025-11-19 12:51:22 +03:00
parent 25b2e2f592
commit a45120b831
4 changed files with 24 additions and 14 deletions

View File

@@ -147,19 +147,23 @@ func (stt *WhisperServer) IsRecording() bool {
func (stt *WhisperServer) microphoneStream(sampleRate int) error {
// Temporarily redirect stderr to suppress ALSA warnings during PortAudio init
origStderr, err := syscall.Dup(syscall.Stderr)
origStderr, errDup := syscall.Dup(syscall.Stderr)
if errDup != nil {
return fmt.Errorf("failed to dup stderr: %w", errDup)
}
nullFD, err := syscall.Open("/dev/null", syscall.O_WRONLY, 0)
if err != nil {
_ = syscall.Close(origStderr) // Close the dup'd fd if open fails
return fmt.Errorf("failed to open /dev/null: %w", err)
}
// redirect stderr
syscall.Dup2(nullFD, syscall.Stderr)
_ = syscall.Dup2(nullFD, syscall.Stderr)
// Initialize PortAudio (this is where ALSA warnings occur)
defer func() {
// Restore stderr
syscall.Dup2(origStderr, syscall.Stderr)
syscall.Close(origStderr)
syscall.Close(nullFD)
_ = syscall.Dup2(origStderr, syscall.Stderr)
_ = syscall.Close(origStderr)
_ = syscall.Close(nullFD)
}()
if err := portaudio.Initialize(); err != nil {
return fmt.Errorf("portaudio init failed: %w", err)

View File

@@ -49,20 +49,24 @@ func (w *WhisperBinary) StartRecording() error {
return errors.New("recording is already in progress")
}
// Temporarily redirect stderr to suppress ALSA warnings during PortAudio init
origStderr, err := syscall.Dup(syscall.Stderr)
origStderr, errDup := syscall.Dup(syscall.Stderr)
if errDup != nil {
return fmt.Errorf("failed to dup stderr: %w", errDup)
}
nullFD, err := syscall.Open("/dev/null", syscall.O_WRONLY, 0)
if err != nil {
_ = syscall.Close(origStderr) // Close the dup'd fd if open fails
return fmt.Errorf("failed to open /dev/null: %w", err)
}
// redirect stderr
syscall.Dup2(nullFD, syscall.Stderr)
_ = syscall.Dup2(nullFD, syscall.Stderr)
// Initialize PortAudio (this is where ALSA warnings occur)
portaudioErr := portaudio.Initialize()
defer func() {
// Restore stderr
syscall.Dup2(origStderr, syscall.Stderr)
syscall.Close(origStderr)
syscall.Close(nullFD)
_ = syscall.Dup2(origStderr, syscall.Stderr)
_ = syscall.Close(origStderr)
_ = syscall.Close(nullFD)
}()
if portaudioErr != nil {
return fmt.Errorf("portaudio init failed: %w", portaudioErr)

View File

@@ -81,7 +81,7 @@ func (p ProviderSQL) SearchClosest(q []float32) ([]models.VectorRow, error) {
return nil, err
}
querySQL := fmt.Sprintf("SELECT embedding, slug, raw_text, filename FROM %s", tableName)
querySQL := "SELECT embeddings, slug, raw_text, filename FROM " + tableName
rows, err := p.db.Query(querySQL)
if err != nil {
return nil, err
@@ -187,7 +187,7 @@ func (p ProviderSQL) ListFiles() ([]string, error) {
// Query both tables and combine results
for _, table := range []string{vecTableName384, vecTableName5120} {
query := fmt.Sprintf("SELECT DISTINCT filename FROM %s", table)
query := "SELECT DISTINCT filename FROM " + table
rows, err := p.db.Query(query)
if err != nil {
// Continue if one table doesn't exist
@@ -233,7 +233,7 @@ func (p ProviderSQL) RemoveEmbByFileName(filename string) error {
}
if len(errors) > 0 {
return fmt.Errorf("errors occurred: %s", fmt.Sprintf("%v", errors))
return fmt.Errorf("errors occurred: %v", errors)
}
return nil

4
tui.go
View File

@@ -825,7 +825,9 @@ func init() {
if err != nil {
msg := "failed to inference user speech; error:" + err.Error()
logger.Error(msg)
notifyUser("stt error", msg)
if err := notifyUser("stt error", msg); err != nil {
logger.Error("failed to notify user", "error", err)
}
return nil
}
if userSpeech != "" {