Awesome Reviewers

Reviewer · Error Handling

Never silently swallow errors

When a function call can fail, never discard the error and fall through as if it succeeded. At minimum log it (at a level that gets noticed, not debug, for user-impacting cases); better yet, propagate it to the caller or fail fast. Silent swallowing routinely produces subtle, hard-to-diagnose bugs: a failed shard/fingerprint-filter parse that is treated as...

Instruction

When a function call can fail, never discard the error and fall through as if it succeeded. At minimum log it (at a level that gets noticed, not debug, for user-impacting cases); better yet, propagate it to the caller or fail fast. Silent swallowing routinely produces subtle, hard-to-diagnose bugs: a failed shard/fingerprint-filter parse that is treated as “no filter” and returns wrong results (discussion on client_fanout.go), an unparseable config-map matcher that is just skipped (discussion on request_chunk_filterer.go), a shard-suffix parse error that is dropped with no trace, an SDK call that can’t return an error but whose failure still needs a logged signal, or r.URL.Query() eating a parse error and silently serving the full unfiltered config instead of a 400. Decide deliberately between “fail open” (skip the bad input and continue, documented as safe because it can only narrow/restrict results) and “fail closed” (return the error / reject the request), and make that decision explicit in a comment next to the handling code so a future reader does not mistake it for an oversight. When you do return an error, also return the zero value for any other result parameters (don’t return partial/garbage data alongside the error) so callers that forget to check err don’t accidentally use bogus data.

Example of the anti-pattern to avoid:

shard, _, err := logql.ParseShard(m.Value)
if err != nil {
    return nil // silently treated as "no shard filter" -> can return wrong results
}

Prefer either returning the error to the caller, or explicitly documenting why ignoring it is safe:

shard, _, err := logql.ParseShard(m.Value)
if err != nil {
    return nil, fmt.Errorf("parsing shard from matcher %q: %w", m.Value, err)
}