fix(logs): track and report journalctl check errors
Address review feedback: capture errors from hasJournalctlLogs calls and include diagnostic information when both user and system service checks fail, improving troubleshooting.
- commit
- 8f6a4dce00992647daa460d35a67e070869bd6a0
- author
- brice · · 2026-01-16 05:11 UTC
- parent
- 6c52399
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
1 file · +15 -2
M internal/app/logs.go +15 -2
| @@ -195,16 +195,29 @@ func hasJournalctl() bool { | |||
| 195 | 195 | // showJournalctlLog displays logs from journalctl. | |
| 196 | 196 | // It first tries user service, then falls back to system service. | |
| 197 | 197 | func showJournalctlLog(follow bool, lines int) error { | |
| 198 | + | var userErr, systemErr error | |
| 199 | + | ||
| 198 | 200 | // Try user service first (works without special permissions) | |
| 199 | - | if hasLogs, _ := hasJournalctlLogs(true); hasLogs { | |
| 201 | + | hasLogs, err := hasJournalctlLogs(true) | |
| 202 | + | if err != nil { | |
| 203 | + | userErr = err | |
| 204 | + | } else if hasLogs { | |
| 200 | 205 | return runJournalctl(follow, lines, true) | |
| 201 | 206 | } | |
| 202 | 207 | ||
| 203 | 208 | // Fall back to system service | |
| 204 | - | if hasLogs, _ := hasJournalctlLogs(false); hasLogs { | |
| 209 | + | hasLogs, err = hasJournalctlLogs(false) | |
| 210 | + | if err != nil { | |
| 211 | + | systemErr = err | |
| 212 | + | } else if hasLogs { | |
| 205 | 213 | return runJournalctl(follow, lines, false) | |
| 206 | 214 | } | |
| 207 | 215 | ||
| 216 | + | // If either check failed with an error, include that information | |
| 217 | + | if userErr != nil || systemErr != nil { | |
| 218 | + | return fmt.Errorf("gordon service not found in journalctl (user: %v, system: %v)", userErr, systemErr) | |
| 219 | + | } | |
| 220 | + | ||
| 208 | 221 | return fmt.Errorf("gordon service not found in journalctl: enable file logging in config.toml or run gordon as a systemd service") | |
| 209 | 222 | } | |
| 210 | 223 | ||
| @@ -195,16 +195,29 @@ func hasJournalctl() bool { | |||||
| 195 | // showJournalctlLog displays logs from journalctl. | 195 | // showJournalctlLog displays logs from journalctl. | ||
| 196 | // It first tries user service, then falls back to system service. | 196 | // It first tries user service, then falls back to system service. | ||
| 197 | func showJournalctlLog(follow bool, lines int) error { | 197 | func showJournalctlLog(follow bool, lines int) error { | ||
| 198 | + | var userErr, systemErr error | |||
| 199 | + | ||||
| 198 | // Try user service first (works without special permissions) | 200 | // Try user service first (works without special permissions) | ||
| 199 | - | if hasLogs, _ := hasJournalctlLogs(true); hasLogs { | 201 | + | hasLogs, err := hasJournalctlLogs(true) |
| 202 | + | if err != nil { | |||
| 203 | + | userErr = err | |||
| 204 | + | } else if hasLogs { | |||
| 200 | return runJournalctl(follow, lines, true) | 205 | return runJournalctl(follow, lines, true) | ||
| 201 | } | 206 | } | ||
| 202 | 207 | ||||
| 203 | // Fall back to system service | 208 | // Fall back to system service | ||
| 204 | - | if hasLogs, _ := hasJournalctlLogs(false); hasLogs { | 209 | + | hasLogs, err = hasJournalctlLogs(false) |
| 210 | + | if err != nil { | |||
| 211 | + | systemErr = err | |||
| 212 | + | } else if hasLogs { | |||
| 205 | return runJournalctl(follow, lines, false) | 213 | return runJournalctl(follow, lines, false) | ||
| 206 | } | 214 | } | ||
| 207 | 215 | ||||
| 216 | + | // If either check failed with an error, include that information | |||
| 217 | + | if userErr != nil || systemErr != nil { | |||
| 218 | + | return fmt.Errorf("gordon service not found in journalctl (user: %v, system: %v)", userErr, systemErr) | |||
| 219 | + | } | |||
| 220 | + | ||||
| 208 | return fmt.Errorf("gordon service not found in journalctl: enable file logging in config.toml or run gordon as a systemd service") | 221 | return fmt.Errorf("gordon service not found in journalctl: enable file logging in config.toml or run gordon as a systemd service") | ||
| 209 | } | 222 | } | ||
| 210 | 223 | ||||