|
| 1 | +{ |
| 2 | + "meta": { |
| 3 | + "language": "en", |
| 4 | + "version": 1 |
| 5 | + }, |
| 6 | + "glossary": { |
| 7 | + "kid": { |
| 8 | + "variable": "name", |
| 9 | + "function": "recipe", |
| 10 | + "object": "thing" |
| 11 | + } |
| 12 | + }, |
| 13 | + "errors": { |
| 14 | + "NameError": { |
| 15 | + "variants": [ |
| 16 | + { |
| 17 | + "title": "This name doesn't exist yet", |
| 18 | + "summary": "Your code uses \"{{name}}\", but it hasn't been created yet. Check {{loc}}. If you meant the text <i>{{name}}</i>, put it in double quotes.", |
| 19 | + "why": "Python needs to see a line that creates \"{{name}}\" before you use it.", |
| 20 | + "steps": [ |
| 21 | + "Make it first (for example: {{name}} = 0).", |
| 22 | + "Check spelling and capital letters." |
| 23 | + ] |
| 24 | + }, |
| 25 | + { |
| 26 | + "if": { |
| 27 | + "match_message": ["is not defined"] |
| 28 | + }, |
| 29 | + "title": "This name doesn't exist here", |
| 30 | + "summary": "\"{{name}}\" might be created somewhere else, but you're using it at {{loc}}. If you meant the text <i>{{name}}</i>, put it in double quotes.", |
| 31 | + "why": "A name created in another place might not be available here.", |
| 32 | + "steps": [ |
| 33 | + "Move the line that makes it to above where you use it.", |
| 34 | + "Or set it here just before you use it." |
| 35 | + ] |
| 36 | + } |
| 37 | + ] |
| 38 | + }, |
| 39 | + |
| 40 | + "UnboundLocalError": { |
| 41 | + "variants": [ |
| 42 | + { |
| 43 | + "title": "Used before it gets a value in this part of the code", |
| 44 | + "summary": "Here, \"{{name}}\" is used at {{loc}} before you give it a value.", |
| 45 | + "why": "Because you assign to this name in this part, Python treats it as local here. It is read before you set it.", |
| 46 | + "steps": [ |
| 47 | + "Give it a value first (add a line like {{name}} = ... before you use it).", |
| 48 | + "If you meant a different value, use a different name here." |
| 49 | + ] |
| 50 | + } |
| 51 | + ] |
| 52 | + }, |
| 53 | + |
| 54 | + "SyntaxError": { |
| 55 | + "variants": [ |
| 56 | + { |
| 57 | + "if": { |
| 58 | + "match_code": ["^(\\s*)(if|for|while|def|class|elif|else|try|except|with)\\b"], |
| 59 | + "not_code": [":\\s*$"] |
| 60 | + }, |
| 61 | + "title": "Missing colon (:) at the end", |
| 62 | + "summary": "This line starts a block and needs a colon at {{loc}}: {{codeLine}}", |
| 63 | + "why": "In Python, lines that start a block must end with a colon.", |
| 64 | + "steps": [ |
| 65 | + "Add a colon (:) at the end of that line." |
| 66 | + ] |
| 67 | + }, |
| 68 | + { |
| 69 | + "title": "The line is incomplete or mismatched", |
| 70 | + "summary": "Something is missing or extra — like a colon, bracket, or quote.", |
| 71 | + "why": "If (), [], {}, :, or quotes don't match, Python can't read the line.", |
| 72 | + "steps": [ |
| 73 | + "Make (), [], and {} come in matching pairs.", |
| 74 | + "Add the missing colon (:).", |
| 75 | + "Use matching opening and closing quotes." |
| 76 | + ] |
| 77 | + } |
| 78 | + ] |
| 79 | + }, |
| 80 | + |
| 81 | + "IndentationError": { |
| 82 | + "variants": [ |
| 83 | + { |
| 84 | + "title": "The indentation doesn't match", |
| 85 | + "summary": "All lines in a block must start in the same column. Fix around {{loc}}.", |
| 86 | + "why": "Python groups code by indentation. Mixing tabs and spaces or uneven indents breaks the block.", |
| 87 | + "steps": [ |
| 88 | + "Use 4 spaces per level (not tabs).", |
| 89 | + "Line up all lines in the block." |
| 90 | + ] |
| 91 | + } |
| 92 | + ] |
| 93 | + }, |
| 94 | + |
| 95 | + "TypeError": { |
| 96 | + "variants": [ |
| 97 | + { |
| 98 | + "title": "These values don't work together", |
| 99 | + "summary": "You're combining different kinds of values (for example, a number and a word).", |
| 100 | + "why": "Operators like + only work with certain kinds together.", |
| 101 | + "steps": [ |
| 102 | + "Change a value to the right kind: int(\"3\") or str(7).", |
| 103 | + "Use an operator that works with these values." |
| 104 | + ] |
| 105 | + } |
| 106 | + ] |
| 107 | + }, |
| 108 | + |
| 109 | + "AttributeError": { |
| 110 | + "variants": [ |
| 111 | + { |
| 112 | + "if": { |
| 113 | + "match_code": ["\\.push\\s*\\("], |
| 114 | + "match_message": ["'push'"] |
| 115 | + }, |
| 116 | + "title": "Lists don't have that feature", |
| 117 | + "summary": "You're calling a list method that doesn't exist.", |
| 118 | + "why": "Lists use .append(value) or .extend([...]). There is no .push().", |
| 119 | + "steps": [ |
| 120 | + "Use list.append(one_item).", |
| 121 | + "Use list.extend([many, items])." |
| 122 | + ] |
| 123 | + }, |
| 124 | + { |
| 125 | + "title": "This thing doesn't have that name after the dot", |
| 126 | + "summary": "The thing you're using doesn't have that attribute or method.", |
| 127 | + "why": "That kind of thing doesn't provide this feature.", |
| 128 | + "steps": [ |
| 129 | + "Check the spelling after the dot.", |
| 130 | + "Use a name that exists for this kind of thing." |
| 131 | + ] |
| 132 | + } |
| 133 | + ] |
| 134 | + }, |
| 135 | + |
| 136 | + "IndexError": { |
| 137 | + "variants": [ |
| 138 | + { |
| 139 | + "title": "That position is outside the list", |
| 140 | + "summary": "You're asking for a list position that isn't there.", |
| 141 | + "why": "List positions start at 0 and stop before the list's length.", |
| 142 | + "steps": [ |
| 143 | + "Check the length with len(the_list).", |
| 144 | + "Use a position number smaller than len(the_list)." |
| 145 | + ] |
| 146 | + } |
| 147 | + ] |
| 148 | + }, |
| 149 | + |
| 150 | + "KeyError": { |
| 151 | + "variants": [ |
| 152 | + { |
| 153 | + "title": "That key isn't in the dictionary", |
| 154 | + "summary": "You looked up a key that the dictionary doesn't have.", |
| 155 | + "why": "The dictionary has no value for that key.", |
| 156 | + "steps": [ |
| 157 | + "Check the exact key (spelling and capital letters).", |
| 158 | + "If it might be missing, use dictionary.get(key, default) or add the key first." |
| 159 | + ] |
| 160 | + } |
| 161 | + ] |
| 162 | + }, |
| 163 | + |
| 164 | + "Other": { |
| 165 | + "variants": [ |
| 166 | + { |
| 167 | + "title": "Python error", |
| 168 | + "summary": "Start with the last line of the message and the highlighted code line.", |
| 169 | + "why": "The last line of the traceback tells you the error type and main cause.", |
| 170 | + "steps": [ |
| 171 | + "Fix one small thing and run again." |
| 172 | + ] |
| 173 | + } |
| 174 | + ] |
| 175 | + } |
| 176 | + } |
| 177 | +} |
0 commit comments