Skip to content

Commit

Permalink
Improve error message with title, description, and examples (#10)
Browse files Browse the repository at this point in the history
* Add source and hover information to error output

For the CLI, only the source (i.e. title property) is added.
FOr the CI, the hover information (title, description, examples) are
added and formatted according to YAMLHover.

* build

* run prettier

* Fix escape sequences in links not being unescaped

* build
  • Loading branch information
AndreasMadsen authored Mar 24, 2024
1 parent 7d24f5d commit 0a58256
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 20 deletions.
2 changes: 1 addition & 1 deletion github-action/dist/index.js

Large diffs are not rendered by default.

33 changes: 20 additions & 13 deletions github-action/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ import * as core from '@actions/core';
import * as path from 'path';
import { YamlVersion } from 'yaml-language-server/out/server/src/languageservice/parser/yamlParser07';
import { SchemaMapping, validateDirectory } from '../src';
import { MarkupContent } from 'vscode-languageserver-types';

import { marked } from 'marked';
import { markedTerminal } from 'marked-terminal';

async function run() {
marked.use(markedTerminal() as any);

let rootPath = process.env['GITHUB_WORKSPACE'] as string;
let relativeToRoot = core.getInput('root', { trimWhitespace: true });
if (relativeToRoot) {
Expand All @@ -29,19 +35,20 @@ async function run() {
if (results && results.length > 0) {
for (const result of results) {
for (const error of result.error) {
core.error(
`${result.filePath}:${error.range.start.line + 1}:${error.range.start.character + 1}: ${
error.message
}`,
{
title: error.message,
file: result.filePath,
startLine: error.range.start.line + 1,
endLine: error.range.end.line + 1,
startColumn: error.range.start.character,
endColumn: error.range.end.character,
},
);
const { diag, hover } = error;
const hoverMessage =
hover && MarkupContent.is(hover.contents)
? `\n\n${marked(hover.contents.value, { gfm: false })}`
: '';

core.error(diag.message + hoverMessage, {
title: `${diag.message}${diag.source ? ' ' + diag.source + '.' : ''}`,
file: result.filePath,
startLine: diag.range.start.line + 1,
endLine: diag.range.end.line + 1,
startColumn: diag.range.start.character,
endColumn: diag.range.end.character,
});
}
}

Expand Down
2 changes: 1 addition & 1 deletion github-action/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = {
),
],
resolve: {
extensions: [ '.ts', '.js' ],
extensions: [ '.ts', '.js', '.json' ],
},
output: {
filename: 'index.js',
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@
"@actions/core": "^1.10.0",
"@types/glob": "^7.1.4",
"@types/jest": "^27.0.2",
"@types/marked-terminal": "^6.0.1",
"@types/node": "^16.9.4",
"jest": "^27.2.1",
"marked": "^11.1.1",
"marked-terminal": "^6.2.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.4.1",
"rimraf": "^3.0.2",
Expand Down
136 changes: 136 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0a58256

Please sign in to comment.