wowprompt

Logging and error handling added to a pasted function

Rewrites a function so it handles failures deliberately and logs useful, structured messages without leaking secrets or personal data. Use it when a script or service fails silently, or when production errors are impossible to trace.

The improved function with error handling and log lines, a table of failure cases with how each is handled and logged, and notes on log levels and sensitive fields
The output this prompt produced, unedited.

The prompt

Role

You are a senior backend engineer who has been on call. You add the logging and error handling that make a 3 a.m. incident short, and nothing that adds noise.

Task

Improve error handling and logging in the function below.

Inputs

  • Language, framework and logging library: [e.g. Python with the logging module, Node.js with pino, PHP with Monolog]
  • Code: [paste the function and anything it calls that matters]
  • Where it runs: [web request, background job, scheduled script, CLI]
  • What should happen on failure: [retry, skip the item and continue, stop and alert, return an error to the user]
  • Sensitive fields in the data: [e.g. email, phone, card details, tokens]

Method

  1. List every way the function can fail: bad input, network errors, timeouts, missing files, database errors, unexpected responses.
  2. Decide for each failure: handle and continue, retry, or raise with context.
  3. Add log lines at the right level: debug for detail, info for normal milestones, warning for handled problems, error for failures that need attention.
  4. Use structured fields, such as an item ID and duration, instead of building long strings.

Output format

  1. The rewritten function in one code block.
  2. | Failure case | How it is handled | Log level | Fields logged |
  3. Changes in behaviour the caller must know about.
  4. A short note on what to alert on.

Quality rules

  • Never catch an exception just to hide it; every caught error is either handled with a reason or raised again with context.
  • Never log passwords, tokens, full card numbers or full personal data; mask or omit them.
  • Keep the function's public signature unless a change is unavoidable, and flag it if so.
  • No log line inside a tight loop at info level or above.
error handlingstructured loggingexception handlinglogging best practicesretry and fallbackproduction debugging

How to run this

Copy the prompt and paste it into Gemini, then set the aspect ratio to 3:4. No reference photo is needed for this one.

The prompt is written in Markdown with each part under its own heading, which is what the copy action hands over. Change one section at a time, keeping the rest intact, so you can tell which change did the work.

Related prompts

All productivity