Initial upload: CLI Explain Fix project with CI/CD workflow
This commit is contained in:
319
knowledge_base/errors.yaml
Normal file
319
knowledge_base/errors.yaml
Normal file
@@ -0,0 +1,319 @@
|
||||
errors:
|
||||
# Python Errors
|
||||
- error_type: ImportError
|
||||
language: python
|
||||
severity: high
|
||||
what_happened: Python couldn't find and import a module or attribute.
|
||||
why_happened: The module you're trying to import doesn't exist, isn't installed, or the attribute doesn't exist in that module. This commonly happens with typos, missing dependencies, or incorrect import paths.
|
||||
how_to_fix:
|
||||
- Check that the package is installed: pip list | grep package-name
|
||||
- Install the package if missing: pip install package-name
|
||||
- Verify the import statement matches the package's documentation
|
||||
- Check for typos in the module or attribute name
|
||||
- If using a virtual environment, ensure it's activated
|
||||
code_snippets:
|
||||
- description: Install missing package
|
||||
code: pip install requests
|
||||
language: bash
|
||||
- description: Correct import
|
||||
code: import requests
|
||||
language: python
|
||||
|
||||
- error_type: ValueError
|
||||
language: python
|
||||
severity: medium
|
||||
what_happened: A function received an argument with the right type but inappropriate value.
|
||||
why_happened: The value passed to the function doesn't meet the expected constraints or is outside the valid range.
|
||||
how_to_fix:
|
||||
- Check the function's documentation for valid input ranges
|
||||
- Add validation before passing the value
|
||||
- Look at the error message for specific constraints
|
||||
- Use try/except to catch invalid inputs
|
||||
code_snippets:
|
||||
- description: Safe conversion
|
||||
code: |
|
||||
try:
|
||||
num = int(user_input)
|
||||
except ValueError:
|
||||
print("Please enter a valid number")
|
||||
language: python
|
||||
|
||||
- error_type: TypeError
|
||||
language: python
|
||||
severity: high
|
||||
what_happened: An operation was performed on an object of inappropriate type.
|
||||
why_happened: Python doesn't support the operation between the types you're using, like adding a string to an integer.
|
||||
how_to_fix:
|
||||
- Check the types of your variables using type()
|
||||
- Convert values to the correct type explicitly
|
||||
- Use isinstance() to check types before operations
|
||||
- Review the function's expected parameter types
|
||||
code_snippets:
|
||||
- description: Type conversion
|
||||
code: |
|
||||
num = int("42") # Convert string to int
|
||||
text = str(42) # Convert int to string
|
||||
language: python
|
||||
|
||||
- error_type: SyntaxError
|
||||
language: python
|
||||
severity: critical
|
||||
what_happened: Python encountered invalid syntax in your code.
|
||||
why_happened: The code doesn't follow Python's syntax rules. This could be missing colons, parentheses, quotes, or incorrect indentation.
|
||||
how_to_fix:
|
||||
- Check the line number mentioned in the error
|
||||
- Look for missing or extra parentheses, brackets, or quotes
|
||||
- Ensure colon after function/class definitions and control flow
|
||||
- Check for incorrect indentation
|
||||
- Ensure strings have matching quotes
|
||||
code_snippets:
|
||||
- description: Common fix
|
||||
code: |
|
||||
# Wrong: if x > 5 print("big")
|
||||
# Correct:
|
||||
if x > 5:
|
||||
print("big")
|
||||
language: python
|
||||
|
||||
- error_type: KeyError
|
||||
language: python
|
||||
severity: medium
|
||||
what_happened: A dictionary key was not found in the dictionary.
|
||||
why_happened: You tried to access a dictionary key that doesn't exist.
|
||||
how_to_fix:
|
||||
- Use dict.get(key) to return None instead of raising an error
|
||||
- Use dict.setdefault(key, default) to set a default value
|
||||
- Check if key exists first: if key in dict
|
||||
- Use try/except to handle the missing key
|
||||
code_snippets:
|
||||
- description: Safe access
|
||||
code: |
|
||||
value = my_dict.get("missing_key", "default")
|
||||
language: python
|
||||
|
||||
- error_type: IndexError
|
||||
language: python
|
||||
severity: medium
|
||||
what_happened: A sequence subscript was out of range.
|
||||
why_happened: You tried to access an index that doesn't exist in the list or tuple.
|
||||
how_to_fix:
|
||||
- Remember Python uses 0-based indexing
|
||||
- Check the length before accessing: len(list)
|
||||
- Use negative indices to access from the end
|
||||
- Remember last index is len(list) - 1
|
||||
code_snippets:
|
||||
- description: Safe indexing
|
||||
code: |
|
||||
if index < len(my_list):
|
||||
value = my_list[index]
|
||||
language: python
|
||||
|
||||
- error_type: AttributeError
|
||||
language: python
|
||||
severity: high
|
||||
what_happened: An object doesn't have the attribute you're trying to access.
|
||||
why_happened: The object type doesn't have the method or attribute you're calling. This often happens with typos or incorrect object types.
|
||||
how_to_fix:
|
||||
- Check the object's type using type()
|
||||
- Verify the attribute name matches the documentation
|
||||
- Use hasattr() to check if attribute exists
|
||||
- Check if you need to call a method with ()
|
||||
code_snippets:
|
||||
- description: Safe attribute access
|
||||
code: |
|
||||
if hasattr(obj, 'attribute'):
|
||||
value = obj.attribute
|
||||
language: python
|
||||
|
||||
- error_type: FileNotFoundError
|
||||
language: python
|
||||
severity: high
|
||||
what_happened: The file or directory you specified doesn't exist.
|
||||
why_happened: You're trying to open a file that doesn't exist at the specified path.
|
||||
how_to_fix:
|
||||
- Check the file path for typos
|
||||
- Use absolute paths to avoid confusion
|
||||
- Check if you're in the correct working directory
|
||||
- Use os.path.exists() to check before opening
|
||||
code_snippets:
|
||||
- description: Check file exists
|
||||
code: |
|
||||
import os
|
||||
if os.path.exists("file.txt"):
|
||||
with open("file.txt") as f:
|
||||
content = f.read()
|
||||
language: python
|
||||
|
||||
# JavaScript Errors
|
||||
- error_type: ReferenceError
|
||||
language: javascript
|
||||
severity: high
|
||||
what_happened: A variable or function that doesn't exist was referenced.
|
||||
why_happened: You're trying to use something that hasn't been declared or is out of scope.
|
||||
how_to_fix:
|
||||
- Check for typos in variable/function names
|
||||
- Ensure variables are declared before use
|
||||
- Check that variables are in scope
|
||||
- Verify you're not using a variable before it's defined
|
||||
code_snippets:
|
||||
- description: Proper declaration
|
||||
code: |
|
||||
// Wrong: console.log(x);
|
||||
// Correct:
|
||||
const x = 10;
|
||||
console.log(x);
|
||||
language: javascript
|
||||
|
||||
- error_type: TypeError
|
||||
language: javascript
|
||||
severity: high
|
||||
what_happened: An operation was performed on a value of inappropriate type.
|
||||
why_happened: The value is null, undefined, or not the expected type for the operation.
|
||||
how_to_fix:
|
||||
- Check if values are null/undefined before use
|
||||
- Use optional chaining: obj?.property
|
||||
- Use typeof to check types
|
||||
- Add null checks with if statements
|
||||
code_snippets:
|
||||
- description: Optional chaining
|
||||
code: |
|
||||
// Safe property access
|
||||
const value = obj?.property ?? "default";
|
||||
language: javascript
|
||||
|
||||
- error_type: SyntaxError
|
||||
language: javascript
|
||||
severity: critical
|
||||
what_happened: JavaScript code contains invalid syntax.
|
||||
why_happened: The code doesn't follow JavaScript's syntax rules.
|
||||
how_to_fix:
|
||||
- Check for missing semicolons, braces, or parentheses
|
||||
- Verify string quotes are properly closed
|
||||
- Check for invalid character sequences
|
||||
- Use a linter to catch syntax issues
|
||||
code_snippets:
|
||||
- description: Common fix
|
||||
code: |
|
||||
// Wrong: if (x > 5 console.log('big')
|
||||
// Correct:
|
||||
if (x > 5) {
|
||||
console.log('big');
|
||||
}
|
||||
language: javascript
|
||||
|
||||
- error_type: RangeError
|
||||
language: javascript
|
||||
severity: medium
|
||||
what_happened: A value is outside the allowed range.
|
||||
why_happened: You passed a value that exceeds the allowed limits for a function or operation.
|
||||
how_to_fix:
|
||||
- Check the allowed range in function documentation
|
||||
- Add validation before calling the function
|
||||
- Use console.log to see the actual values
|
||||
code_snippets:
|
||||
- description: Array length fix
|
||||
code: |
|
||||
// Wrong: arr[100] when arr has 5 elements
|
||||
// Correct: arr[4] for the last element
|
||||
language: javascript
|
||||
|
||||
# Go Errors
|
||||
- error_type: panic
|
||||
language: go
|
||||
severity: critical
|
||||
what_happened: Go encountered a runtime panic.
|
||||
why_happened: The program encountered an unrecoverable error, such as nil pointer dereference or array out of bounds.
|
||||
how_to_fix:
|
||||
- Check the panic message for the cause
|
||||
- Use defer and recover to handle panics
|
||||
- Add nil checks before dereferencing pointers
|
||||
- Ensure array indices are within bounds
|
||||
- Check for proper initialization
|
||||
code_snippets:
|
||||
- description: Nil check
|
||||
code: |
|
||||
if ptr != nil {
|
||||
fmt.Println(*ptr)
|
||||
}
|
||||
language: go
|
||||
|
||||
# Rust Errors
|
||||
- error_type: panic
|
||||
language: rust
|
||||
severity: critical
|
||||
what_happened: Rust encountered a runtime panic.
|
||||
why_happened: The program called panic!() or encountered an unrecoverable error condition.
|
||||
how_to_fix:
|
||||
- Check the panic message for the cause
|
||||
- Use ? operator for error propagation
|
||||
- Check for unwrap() calls that might panic
|
||||
- Use match or if let for proper error handling
|
||||
code_snippets:
|
||||
- description: Proper error handling
|
||||
code: |
|
||||
match some_result {
|
||||
Ok(value) => println!("{}", value),
|
||||
Err(e) => eprintln!("Error: {}", e),
|
||||
}
|
||||
language: rust
|
||||
|
||||
# CLI Generic Errors
|
||||
- error_type: GenericError
|
||||
language: cli
|
||||
severity: medium
|
||||
what_happened: A command or tool returned an error.
|
||||
why_happened: The command failed for some reason. Check the specific error message for details.
|
||||
how_to_fix:
|
||||
- Read the full error message for specific details
|
||||
- Check the command's documentation
|
||||
- Verify all required arguments are provided
|
||||
- Check if the tool/command is installed
|
||||
- Look for typos in the command or arguments
|
||||
code_snippets: []
|
||||
|
||||
# JSON/YAML Parse Errors
|
||||
- error_type: JSONParseError
|
||||
language: json
|
||||
severity: high
|
||||
what_happened: The JSON data is malformed or invalid.
|
||||
why_happened: The JSON string doesn't follow JSON syntax rules - missing quotes, trailing commas, or incorrect structure.
|
||||
how_to_fix:
|
||||
- Validate the JSON with a linter or online tool
|
||||
- Check for missing commas between elements
|
||||
- Ensure all keys are in double quotes
|
||||
- Check for trailing commas (not allowed in JSON)
|
||||
- Verify string values are properly escaped
|
||||
code_snippets:
|
||||
- description: Valid JSON example
|
||||
code: |
|
||||
{
|
||||
"key": "value",
|
||||
"number": 42,
|
||||
"boolean": true,
|
||||
"array": [1, 2, 3],
|
||||
"null": null
|
||||
}
|
||||
language: json
|
||||
|
||||
- error_type: YAMLParseError
|
||||
language: yaml
|
||||
severity: high
|
||||
what_happened: The YAML data is malformed or invalid.
|
||||
why_happened: The YAML string doesn't follow YAML syntax rules - indentation errors, invalid anchors, or incorrect structure.
|
||||
how_to_fix:
|
||||
- Use consistent indentation (spaces, not tabs)
|
||||
- Check for proper list and dict syntax
|
||||
- Validate with a YAML linter
|
||||
- Ensure special characters are properly escaped
|
||||
code_snippets:
|
||||
- description: Valid YAML example
|
||||
code: |
|
||||
key: value
|
||||
number: 42
|
||||
boolean: true
|
||||
list:
|
||||
- item1
|
||||
- item2
|
||||
nested:
|
||||
inner: value
|
||||
language: yaml
|
||||
Reference in New Issue
Block a user