Give IDE chat the evidence behind an error
How to give IDE chat the code and error context it needs to explain failures and decide whether to use Optimize or Refactor on selected code.
Amazon Q Developer IDE chat can explain a code snippet and help you debug it. When you ask a question, Q uses the currently open file as context, including its programming language and file path. That gives Q the code you are looking at, but it does not tell Q what happened when you ran it.
Put the observed failure in the prompt: the exact error, the relevant stack trace lines if available, and what you expected instead. If the failing line calls a helper defined elsewhere, specify that file as additional context. You can specify files, folders, or the whole workspace during a chat session; start with the code that bears directly on the failure.
For example, if a report fails only when the input list is empty, say so and ask Q to explain which expression fails and suggest a check that would confirm its explanation. Treat the suggested cause as something to verify, not as a diagnosis you can skip testing.
Next up: Sort the statements on what you just read.