Skip to content

Commit

Permalink
chore(list-different): catch and displays error
Browse files Browse the repository at this point in the history
  • Loading branch information
capsuleman authored and skovy committed Jan 2, 2022
1 parent 8761c9a commit a6b90ee
Showing 1 changed file with 33 additions and 26 deletions.
59 changes: 33 additions & 26 deletions lib/core/list-different.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,37 +34,44 @@ export const checkFile = (
options: MainOptions
): Promise<boolean> => {
return new Promise((resolve) =>
fileToClassNames(file, options).then(async (classNames) => {
const typeDefinition = await classNamesToTypeDefinitions({
classNames: classNames,
...options,
});
fileToClassNames(file, options)
.then(async (classNames) => {
const typeDefinition = await classNamesToTypeDefinitions({
classNames: classNames,
...options,
});

if (!typeDefinition) {
// Assume if no type defs are necessary it's fine
resolve(true);
return;
}
if (!typeDefinition) {
// Assume if no type defs are necessary it's fine
resolve(true);
return;
}

const path = getTypeDefinitionPath(file);
const path = getTypeDefinitionPath(file);

if (!fs.existsSync(path)) {
alerts.error(
`[INVALID TYPES] Type file needs to be generated for ${file} `
);
resolve(false);
return;
}
if (!fs.existsSync(path)) {
alerts.error(
`[INVALID TYPES] Type file needs to be generated for ${file} `
);
resolve(false);
return;
}

const content = fs.readFileSync(path, { encoding: "utf8" });
const content = fs.readFileSync(path, { encoding: "utf8" });

if (content !== typeDefinition) {
alerts.error(`[INVALID TYPES] Check type definitions for ${file}`);
resolve(false);
return;
}
if (content !== typeDefinition) {
alerts.error(`[INVALID TYPES] Check type definitions for ${file}`);
resolve(false);
return;
}

resolve(true);
})
resolve(true);
})
.catch((error) => {
alerts.error(
`An error occurred checking ${file}:\n${JSON.stringify(error)}`
);
resolve(false);
})
);
};

0 comments on commit a6b90ee

Please sign in to comment.