pi-lens
Version:
Real-time code feedback for pi — LSP, linters, formatters, type-checking, structural analysis & booboo
50 lines (40 loc) • 1.05 kB
YAML
# Go Reliability
# Detects process-terminating log calls in non-boundary code.
id: go-log-fatal
name: log.Fatal / log.Panic Call
severity: warning
category: reliability
defect_class: safety
inline_tier: warning
language: go
message: "log.Fatal/log.Panic terminates execution — prefer returning errors from core logic"
description: |
`log.Fatal*` exits the process and `log.Panic*` panics. In shared/internal logic,
this makes control flow hard to test and recover.
✅ FIX: return errors upward and let program entrypoints decide termination policy.
query: |
(call_expression
function: (selector_expression
operand: (identifier) @PKG
field: (field_identifier) @METHOD)
arguments: (argument_list) @ARGS
(#eq? @PKG "log")
(#match? @METHOD "^(Fatal|Fatalf|Fatalln|Panic|Panicf|Panicln)$"))
metavars:
- PKG
- METHOD
- ARGS
has_fix: false
tags:
- go
- reliability
- testability
examples:
bad: |
if err != nil {
log.Fatal(err)
}
good: |
if err != nil {
return err
}