A shared folder with AI prompts and code snippets
From workspace: Replit
Team: AI Prompts
Total snippets: 8
8 snippets
Fix a Flask bug where missing form data causes a crash.
This line throws a KeyError if the 'username' field is missing. Make it safe while preserving access to the form. Code: username = request.form['username']
Avoid panic due to accessing uninitialized slice in Go.
This Go code panics due to accessing an empty slice. Explain what causes it and rewrite it with a safe guard. Code: package main import "fmt" func main() { var arr []int fmt.Println(arr[0]) }
Fix function that crashes when input is None
This function crashes when given `None` instead of a list. Add type checking and make it safe for invalid input. Code: def find_even(numbers): for i in range(len(numbers)): if numbers[i] % 2 == 0: return i return...
Fix undefined function error in a React component.
This React component throws an "undefined is not a function" error. Debug the root cause and rewrite to prevent runtime failure. Component: function MyComponent({ items }) { return ( <ul> {items.map(item =>...
Fix SQL join that returns more rows than expected.
This SQL query returns more rows than expected. Investigate: – Is there a join mismatch or missing constraint? – Are duplicates introduced via many-to-one? Rewrite the query to fetch only distinct user-order pairs. Query: SELECT users.name,...
Diagnose a classic closure issue in a loop using setTimeout.
This JavaScript loop prints `5` five times instead of `0, 1, 2, 3, 4`. Explain why and rewrite it to fix the closure issue. Code: for (var i = 0; i < 5; i++) { setTimeout(() => console.log(i), 100); }
Find the issue causing an Express route to crash on POST request.
This Node.js Express route crashes when a POST request is made. Debug the issue and return a corrected, secure version. Check: – req.body may be undefined if middleware is missing – Handle missing input gracefully Code: app.post('/submit',...
Debug a TypeError caused by incompatible data types in a function.
Analyze the following Python function that raises a `TypeError` during execution. Add inline explanation and rewrite the fixed version. Example: – Understand cause of failure from traceback – Suggest type-safe handling Code: def add_items(a,...