Rulesnorthwind-fail-fast-env-validation

northwind-fail-fast-env-validation

info

northwind/reliability/fail-fast-env-validation

Docs page ↗

new Northwind(process.env.NORTHWIND_API_KEY!) is called with no presence check — the non-null assertion silences TypeScript and defers the failure to the first charge.

7

codebases affected, of 58

12%

of everything we scanned

no docs fix scored yet

0

docs commits aimed at this

Where it’s failing

Northwind client is constructed from an env var with no presence check.

what we find

what we change it to

import { Northwind } from 'northwind-node'
const northwind = new Northwind(process.env.NORTHWIND_API_KEY!)
// "!" hides the missing var until the first charge fails
import { Northwind } from 'northwind-node'
const apiKey = process.env.NORTHWIND_API_KEY
if (!apiKey) throw new Error('NORTHWIND_API_KEY must be set')
const northwind = new Northwind(apiKey)

Read the variable into a local, throw an error naming it if unset, then construct the client — do this at module load so the process fails at boot rather than on a customer’s request.

Metadata

Category
reliability
Type
suggestion
Severity
info
Recommended
yes
Languages
javascriptpython

Live telemetry

7 / 58 scans

Fired in 12% of scanned codebases.

After every docs commit

No docs commits target this rule yet. When one merges, the next weeks of scans re-score it here.

A fix for your docs page

Wherever this rule fires, a page on your docs site taught it. api-doctor writes the edit and opens it as a pull request on your docs repo — you review and merge.

No fix yet

Draft a docs fix for this rule

api-doctor writes the docs change from the fire pattern — you review it