Invental/Review lessons/Code that silently does the wrong thing

Code that silently does the wrong thing

Copy a tool’s credential lookup order exactly

When you re-implement another tool's lookup rules (credentials, config files, env precedence), copy its order and its failure behaviour exactly, read from its source, or users get different credentials in your tool than in theirs.

01 · Before and afterThe pattern

TypeScript
// lookup order mirrors the reference tool; a broken source falls through, never crashes
async function getCreds(cfg: DockerConfig, registry: string) {
  const helper = cfg.credHelpers?.[registry] ?? cfg.credsStore;
  if (helper) {
    const fromHelper = await tryHelper(helper, registry); // returns undefined on exit≠0 or non-JSON
    if (fromHelper) return fromHelper;
  }
  return cfg.auths?.[registry] ?? (hasNoAuthConfig(cfg) ? await tryHelper(platformDefault(), registry) : undefined);
}

02 · Run it on your appThe check

If your tool reads Docker or cloud credentials, does it pick the same credentials, in the same order, as the official CLI on the same machine?

If the honest answer is no or not sure, this is worth a look before it reaches production.

Want this checked on your code?

Tell us what you are building and what worries you. We match a senior reviewer to your code and confirm scope before anything starts.

— Get in touch
hi@invental.co ↗
— Or
— What to include

A link or short description of the code or system, what you want checked, your stack, and when you need the answer. No repository access is needed until scope is agreed.

— Or leave a note
We reply within one business day.