|
| 1 | +--- |
| 2 | +synopsis: Show source of project parse error or warning |
| 3 | +packages: [cabal-install] |
| 4 | +prs: 10644 |
| 5 | +issues: 10635 |
| 6 | +--- |
| 7 | + |
| 8 | +Improves warning and error messages shown when parsing project files and their |
| 9 | +imports. |
| 10 | + |
| 11 | +## Warning Messages |
| 12 | + |
| 13 | +To trigger these warning messages, the examples use badly formed comments that |
| 14 | +have a single dash instead of two as is required of a line comment in `.cabal` |
| 15 | +and `.project` files (and imported `.config` files). |
| 16 | + |
| 17 | +* Before the fix: |
| 18 | + |
| 19 | + The `cabal.project` file name is repeated. Warnings are misattributed to |
| 20 | + having been in the project rather than from a configuration file imported by |
| 21 | + the project. Warnings are shown in reverse line number order. |
| 22 | + |
| 23 | + ``` |
| 24 | + $ ~/.ghcup/bin/cabal-3.12.1.0 build all --dry-run |
| 25 | + ... |
| 26 | + Warning: |
| 27 | + /.../ParseWarningProvenance/cabal.project, |
| 28 | + cabal.project, cabal.project, cabal.project, cabal.project: Unrecognized |
| 29 | + section '-' on line 123 |
| 30 | + /.../ParseWarningProvenance/cabal.project, |
| 31 | + cabal.project, cabal.project, cabal.project, cabal.project: Unrecognized |
| 32 | + section '-' on line 3 |
| 33 | + /.../ParseWarningProvenance/cabal.project, |
| 34 | + cabal.project, cabal.project, cabal.project, cabal.project: Unrecognized |
| 35 | + section '-' on line 2 |
| 36 | + /.../ParseWarningProvenance/cabal.project, |
| 37 | + cabal.project, cabal.project, cabal.project, cabal.project: Unrecognized |
| 38 | + section '-' on line 1 |
| 39 | + /.../ParseWarningProvenance/cabal.project, |
| 40 | + cabal.project, cabal.project, cabal.project, cabal.project: Unrecognized |
| 41 | + section '-' on line 123 |
| 42 | + /.../ParseWarningProvenance/cabal.project, |
| 43 | + cabal.project, cabal.project, cabal.project, cabal.project: Unrecognized |
| 44 | + section '-' on line 3 |
| 45 | + /.../ParseWarningProvenance/cabal.project, |
| 46 | + cabal.project, cabal.project, cabal.project, cabal.project: Unrecognized |
| 47 | + section '-' on line 2 |
| 48 | + /.../ParseWarningProvenance/cabal.project, |
| 49 | + cabal.project, cabal.project, cabal.project, cabal.project: Unrecognized |
| 50 | + section '-' on line 1 |
| 51 | + ``` |
| 52 | + |
| 53 | +* After the fix: |
| 54 | + |
| 55 | + The warnings are shown in a list. For warnings within the same `.project` or |
| 56 | + imported `.config` file, warnings are sorted by line number. The file that |
| 57 | + is the source of the warning is shown. |
| 58 | + |
| 59 | + |
| 60 | + ``` |
| 61 | + $ cabal build all --dry-run |
| 62 | + ... |
| 63 | + Warnings found while parsing the project file, cabal.project: |
| 64 | + - dir-x/a.config: Unrecognized section '-' on line 1 |
| 65 | + - dir-x/a.config: Unrecognized section '-' on line 2 |
| 66 | + - dir-x/a.config: Unrecognized section '-' on line 3 |
| 67 | + - dir-y/a.config: Unrecognized section '-' on line 123 |
| 68 | + - x.config: Unrecognized section '-' on line 1 |
| 69 | + - x.config: Unrecognized section '-' on line 2 |
| 70 | + - x.config: Unrecognized section '-' on line 3 |
| 71 | + - y.config: Unrecognized section '-' on line 123 |
| 72 | + ``` |
| 73 | + |
| 74 | +## Error Messages from Project |
| 75 | + |
| 76 | +To trigger these error messages, the examples use badly formed conditions: |
| 77 | + |
| 78 | +``` |
| 79 | +$ cat cabal.project |
| 80 | +-- The following failing condition is not on the first line so we can check the |
| 81 | +-- line number: |
| 82 | +if _ |
| 83 | +``` |
| 84 | + |
| 85 | +* Before the fix: |
| 86 | + |
| 87 | + The parse error is shown with hard line breaks. |
| 88 | + |
| 89 | + ``` |
| 90 | + $ ~/.ghcup/bin/cabal-3.12.1.0 build all --dry-run |
| 91 | + ... |
| 92 | + Error: [Cabal-7090] |
| 93 | + Error parsing project file /.../ParseErrorProvenance/cabal.project:3: |
| 94 | + "<condition>" (line 1, column 1): |
| 95 | + unexpected SecArgName (Position 1 4) "_" |
| 96 | + ``` |
| 97 | + |
| 98 | +* After the fix: |
| 99 | + |
| 100 | + The snippet that failed to parse may be shown and the parse error is shown |
| 101 | + as one line, with no hard line breaks. |
| 102 | + |
| 103 | + ``` |
| 104 | + $ cabal build all --dry-run |
| 105 | + ... |
| 106 | + Error: [Cabal-7090] |
| 107 | + Error parsing project file cabal.project:3: |
| 108 | + - Failed to parse 'if(_)' with error: |
| 109 | + "<condition>" (line 1, column 1): unexpected SecArgName (Position 1 4) "_" |
| 110 | + ``` |
| 111 | + |
| 112 | +## Error Messages from Imported Config |
| 113 | + |
| 114 | +With the same setup but now with the error in an imported file: |
| 115 | + |
| 116 | +``` |
| 117 | +$ cat elif.project |
| 118 | +import: dir-elif/elif.config |
| 119 | + |
| 120 | +$ cat dir-elif/elif.config |
| 121 | +-- The following failing condition is not on the first line so we can check the |
| 122 | +-- line number: |
| 123 | +if false |
| 124 | +elif _ |
| 125 | +``` |
| 126 | + |
| 127 | +* Before the fix: |
| 128 | + |
| 129 | + The project rather than the imported configuration file is shown as the source file. |
| 130 | + |
| 131 | + ``` |
| 132 | + $ ~/.ghcup/bin/cabal-3.12.1.0 build all --dry-run |
| 133 | + ... |
| 134 | + Error: [Cabal-7090] |
| 135 | + Error parsing project file /.../ParseErrorProvenance/elif.project:4: |
| 136 | + "<condition>" (line 1, column 1): |
| 137 | + unexpected SecArgName (Position 1 6) "_" |
| 138 | + ``` |
| 139 | + |
| 140 | +* After the fix: |
| 141 | + |
| 142 | + The imported configuration file is shown as the source with a snippet of the error. |
| 143 | + |
| 144 | + ``` |
| 145 | + $ cabal build all --dry-run |
| 146 | + ... |
| 147 | + Error: [Cabal-7090] |
| 148 | + Error parsing project file dir-elif/elif.config:4: |
| 149 | + - dir-elif/elif.config |
| 150 | + imported by: elif.project |
| 151 | + - Failed to parse 'elif(_)' with error: |
| 152 | + "<condition>" (line 1, column 1): unexpected SecArgName (Position 1 6) "_" |
| 153 | + ``` |
0 commit comments