Skip to content

Commit

Permalink
fix: improve undefined handling (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
golota60 committed Jun 18, 2022
1 parent c64b3c8 commit f567131
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/helpers/systeminformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ export const getDisplaysAndGraphicsCards =
const gpu = await sysinf.graphics();

const gpuInfo = gpu.controllers.map(
(gpu: sysinf.Systeminformation.GraphicsControllerData) => gpu.model
(gpu: sysinf.Systeminformation.GraphicsControllerData) =>
gpu?.model || ''
);
const displays = gpu.displays
.map((gpu: sysinf.Systeminformation.GraphicsDisplayData) =>
Expand Down Expand Up @@ -127,7 +128,7 @@ export const getSysInfOsInfo = async (): Promise<OSInfoInterface> => {
export const getHWInfo = async (): Promise<string> => {
try {
const hwInfo = await sysinf.system();
return hwInfo.model;
return hwInfo?.model || '';
} catch (err) {
console.error(`Error when reading hardware info: ${err}`);
return errorMessage;
Expand Down
8 changes: 5 additions & 3 deletions src/yayfetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ async function returnPickedData(
if (valuesToDisplay.includes('CPUs')) {
pickedVals.push(
`${color ? getColoredText('CPU:', color, { bolded: true }) : 'CPU:'} ${
os.cpus()[0].model
os.cpus()?.[0]?.model || ''
}`
);
}
Expand All @@ -163,7 +163,7 @@ async function returnPickedData(
pickedVals.push(
`${
color ? getColoredText('GPU(s):', color, { bolded: true }) : 'GPU(s)'
} ${allData.graphicsInfo.gpuInfo}`
} ${allData?.graphicsInfo?.gpuInfo}`
);
}

Expand All @@ -173,7 +173,7 @@ async function returnPickedData(
color
? getColoredText('Display(s):', color, { bolded: true })
: 'Display(s):'
} ${allData.graphicsInfo.displays}`
} ${allData?.graphicsInfo?.displays}`
);
}

Expand Down Expand Up @@ -279,6 +279,8 @@ yargs
);
}

infoToPrint = infoToPrint.filter((e) => e);

/* Add custom lines if specified */
if (customLines) {
const customLinesParsed =
Expand Down

0 comments on commit f567131

Please sign in to comment.