Skip to content
This repository has been archived by the owner on Jul 23, 2018. It is now read-only.

Plotter crashes and burns on stroke with non-existent tool #14

Closed
ju5t opened this issue Apr 24, 2018 · 6 comments
Closed

Plotter crashes and burns on stroke with non-existent tool #14

ju5t opened this issue Apr 24, 2018 · 6 comments
Labels

Comments

@ju5t
Copy link

ju5t commented Apr 24, 2018

I ran into a problem today and for some reason I can't seem to try {} catch {} my way out of it. I get the following error when trying to parse gerber files that were created with Vutrax.

/usr/local/lib/node_modules/gerber-to-svg/node_modules/gerber-plotter/lib/_operate.js:358
  if (!region && (tool.trace.length === 0)) {
                       ^

TypeError: Cannot read property 'trace' of null
    at interpolate (/usr/local/lib/node_modules/gerber-to-svg/node_modules/gerber-plotter/lib/_operate.js:358:24)
    at operate (/usr/local/lib/node_modules/gerber-to-svg/node_modules/gerber-plotter/lib/_operate.js:405:13)
    at Plotter._transform (/usr/local/lib/node_modules/gerber-to-svg/node_modules/gerber-plotter/lib/plotter.js:177:18)
    at Plotter.Transform._read (/usr/local/lib/node_modules/gerber-to-svg/node_modules/readable-stream/lib/_stream_transform.js:184:10)
    at Plotter.Transform._write (/usr/local/lib/node_modules/gerber-to-svg/node_modules/readable-stream/lib/_stream_transform.js:172:83)
    at doWrite (/usr/local/lib/node_modules/gerber-to-svg/node_modules/readable-stream/lib/_stream_writable.js:418:64)
    at writeOrBuffer (/usr/local/lib/node_modules/gerber-to-svg/node_modules/readable-stream/lib/_stream_writable.js:407:5)
    at Plotter.Writable.write (/usr/local/lib/node_modules/gerber-to-svg/node_modules/readable-stream/lib/_stream_writable.js:334:11)
    at Parser.ondata (/usr/local/lib/node_modules/gerber-to-svg/node_modules/readable-stream/lib/_stream_readable.js:619:20)
    at Parser.emit (events.js:180:13)

@mcous I can send you the gerber files via e-mail if that helps.

@mcous
Copy link
Owner

mcous commented Apr 24, 2018

@ju5t that's pretty odd. Gerber file would be super helpful if available

@mcous mcous added the bug label Apr 24, 2018
@mcous mcous changed the title TypeError: Cannot read property 'trace' of null Plotter crashes and burns on stroke with non-existent tool Apr 24, 2018
@mcous
Copy link
Owner

mcous commented Apr 24, 2018

@ju5t turns out this is a bug in plotter exposed by a bug in the parser which is actually causing your problems: mcous/gerber-parser#23. TL;DR: gerber-parser thinks your Gerber files are drill files because they start with a newline.

As a workaround until the parser is fixed, you could look into passing the filetype option to gerber-to-svg to force the parser to use the correct type. Assuming whats-that-gerber is already involved, you could probably get away with something like:

const whatsThatGerber = require('whats-that-gerber')
const gerberToSvg = require('gerber-to-svg')
// ...
const filename = getFilenameSomehow()
const layerType = whatsThatGerber(filename)
// ...
const converter = gerberToSvg(fs.createReadStream(filename), {
  id: getIdSomehow(),
  filetype: (layerType === 'drl') ? 'drill' : 'gerber'
})
// ...

@ju5t
Copy link
Author

ju5t commented Apr 24, 2018

Got it. I don't think it'll be that easy for us to implement the workaround because we're using pcb-stackup in our project. It's not a major problem, I'll figure out how to catch it for now so we can display a user friendly error.

@mcous
Copy link
Owner

mcous commented Apr 24, 2018

@ju5t pcb-stackup still has the ability to pass options into gerber-to-svg

const fs = require('fs')
const pcbStackup = require('pcb-stackup')
const whatsThatGerber = require('whats-that-gerber')
const shortId = require('shortid')

const fileNames = [
  '/path/to/board-F.Cu.gtl',
  '/path/to/board-F.Mask.gts',
  '/path/to/board-F.SilkS.gto',
  '/path/to/board-F.Paste.gtp',
  '/path/to/board-B.Cu.gbl',
  '/path/to/board-B.Mask.gbs',
  '/path/to/board-B.SilkS.gbo',
  '/path/to/board-B.Paste.gbp',
  '/path/to/board-Edge.Cuts.gm1',
  '/path/to/board.drl',
  '/path/to/board-NPTH.drl',
]

const layers = fileNames.map(filename => ({
  filename,
  gerber: fs.createReadStream(path),
  options: {
    id: shortId.generate()
    filetype: (layerType === 'drl') ? 'drill' : 'gerber'
  }
}))

pcbStackup(layers, (error, stackup) => {
  if (error) return console.error(error)

  console.log(stackup.top.svg) // logs "<svg ... </svg>"
  console.log(stackup.bottom.svg) // logs "<svg ... </svg>"
})

@ju5t
Copy link
Author

ju5t commented Apr 24, 2018

@mcous thanks for the example. I've tested the workaround locally and that works.

@mcous
Copy link
Owner

mcous commented Jul 22, 2018

Closing in favor of tracespace/tracespace#83

@mcous mcous closed this as completed Jul 22, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants