X Tutup
Skip to content

fix: prevent potential error by adding null check for tool.trace#432

Open
AyushKanani07 wants to merge 1 commit intotracespace:masterfrom
AyushKanani07:master
Open

fix: prevent potential error by adding null check for tool.trace#432
AyushKanani07 wants to merge 1 commit intotracespace:masterfrom
AyushKanani07:master

Conversation

@AyushKanani07
Copy link

ErrorGerber.zip

While converting a Gerber ZIP file to SVG using the PCB Stackup library, I encountered a TypeError in the plotter.js file within the gerber-plotter package. This issue causes the Node.js server to crash, making it impossible to proceed with the conversion.

Error Details
The error occurs when running the following code:

const layers = files.map(unzipFile => ({
    filename: unzipFile,
    gerber: fs.createReadStream(path.join(unzip_gerber_dir, unzipFile)),
}));
const stackup = await pcbStackup(layers);

When calling pcbStackup(layers), the Gerber Plotter package throws a TypeError due to tool.trace being undefined.
Error:
if (!this._region && tool.trace.length === 1) {
^
TypeError: Cannot read properties of null (reading 'trace')

The error originates from plotter.js, where the code attempts to access .length on tool.trace, which is null or undefined.

Since the error is unhandled, it crashes the entire Node.js server instead of failing gracefully.

Root Cause

  • The provided Gerber ZIP file has formatting issues, leading to tool.trace being undefined in certain cases.
  • The Gerber Plotter package does not currently check for null values before accessing .length.

Solution

  • Added a null check for tool.trace in plotter.js, ensuring that .length is only accessed when tool.trace is valid.
  • Prevented the error from propagating and crashing the Node.js server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

X Tutup