OpenSCAD Wrong line indication on import error messages
Open
Nobody has claimed this yet.
BUG
data import
- Dominant language
- JavaScript
- Stars
- 3.2k
- Forks
- 564
- PR merge metrics
- No merged PRs in 30d
Description
Expected Behavior
When an error is encountered, report the correct line number.
Actual Behavior
Under Window, the line number reported is 2 * the actual line number, probably due to \r\n counted as two lines.
Steps to Reproduce the Problem
- Create a fake SCAD file with a few comment lines, then a dummy error:
test.scad:
//a
//b
//c
xxxxx
And the container OpenJSCAD file:
var parser = require('@jscad/openscad-openjscad-translator')
var fs = require('fs')
var openSCADText = fs.readFileSync("test.scad", "UTF8")
var openJSCADResult = parser.parse(openSCADText)
console.log(openJSCADResult)
- Now run it:
node ./cli.js test.js
JSCAD: generating output
from: test.js
to: test.stl (STereoLithography, ASCII)
Function {
message: "Parse error on line 7:\n\r\r\rxxxxx\r\n---------^\nExpecting '(', '=', got '1'",
hash: {
text: '',
token: 1,
line: 8,
loc: { first_line: 7, last_line: 7, first_column: 0, last_column: 5 },
expected: [ "'('", "'='" ]
}
}
- As you can see, an error is reported for line 8, not 4.
Specifications
- Version: Release : 2022 MAR 03
- Platform: Windows 10
- Environment: Chrome (Version 98.0.4758.102 (Official Build) (64-bit)), Latest NodsJS LTS (16.14.0), npm 8.3.1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with the shown test.scad and test.js inputs, running them through cli.js and parser.parse. Trace how the parser reports line and location values for Windows-style line endings. Done means the reported error line matches the actual source line in the reproduction without breaking the existing error output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100