> ## Documentation Index
> Fetch the complete documentation index at: https://loadwise.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# go-defer-before-error-check

> A Go defer closes a resource before its error is checked, so a failed open dereferences nil.

## What it flags

`defer resp.Body.Close()`, or `defer rows.Close()` after `Query`/`QueryContext`, runs before the call's error result is checked, whatever the error variable is named, so a failed call defers `Close` on a nil value and panics. `os.Open` files are accepted, since `Close` on a nil `*os.File` returns an error instead.

## Configuration

Set the rule to `"off"` in `loadwise.config.json` to drop its findings:

```json theme={null}
{
  "rules": { "go-defer-before-error-check": "off" }
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.