Skip to content

Commit

Permalink
Improve error messages when front-matter is copy-pasted incorrectly
Browse files Browse the repository at this point in the history
Closes #25
  • Loading branch information
kachkaev committed Mar 17, 2019
1 parent 2572105 commit d0daae9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/literate-elm/src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,14 @@ const convertErrorsToMessages = (
};

const getErrorMessageText = (error): string => {
if (error.title === "UNKNOWN IMPORT") {
// Unknown imports form a special case. It is not reasonable to suggest looking into elm.json and source-directories
// as this is causing confusion in the literate-elm environment.
const failedImport = _.get(error, ["message", 1, "string"]);
if (failedImport) {
return `Could not ${failedImport}. Please make sure you have specified all dependencies on third-party Elm modules.`;
}
}
if (_.isArray(error.message)) {
const text = error.message
.map((chunk) => {
Expand Down
11 changes: 11 additions & 0 deletions packages/litvis/src/document/frontmatter/lintElm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,16 @@ export default (dataWithPosition, document: LitvisDocument): void => {
);
});
}
if (dataWithPosition.dependencies && (!elm || !elm.dependencies)) {
const elmPosition = getPosition(dataWithPosition.elm);
const dependenciesPosition = getPosition(dataWithPosition.dependencies);
if (dependenciesPosition.start.line > elmPosition.end.line) {
document.message(
`It seems that you are missing indentation before ‘dependencies’ and its sub-nodes. Without leading spaces, the value is not considered as a child node of ‘elm’.`,
dependenciesPosition,
"litvis:frontmatter:elm:dependencies",
);
}
}
}
};

0 comments on commit d0daae9

Please sign in to comment.