Thanks to visit codestin.com
Credit goes to github.com

Skip to content

chore(website): surface internal errors in playground #5462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/website/src/components/ErrorsViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import IconExternalLink from '@theme/IconExternalLink';
import styles from './ErrorsViewer.module.css';

export interface ErrorsViewerProps {
readonly value?: ErrorGroup[];
readonly value?: ErrorGroup[] | Error;
}

export interface ErrorBlockProps {
Expand Down Expand Up @@ -100,6 +100,17 @@ export default function ErrorsViewer({
setIsLocked(false);
}, [value]);

if (value && !Array.isArray(value)) {
return (
<div className={styles.list}>
<div className="margin-top--sm">
<h4>ESLint internal error</h4>
{value?.stack}
</div>
</div>
);
}

return (
<div className={styles.list}>
{value?.map(({ group, uri, items }) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/website/src/components/Playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function Playground(): JSX.Element {
const [esAst, setEsAst] = useState<TSESTree.Program | null>();
const [tsAst, setTsAST] = useState<SourceFile | null>();
const [scope, setScope] = useState<Record<string, unknown> | null>();
const [markers, setMarkers] = useState<ErrorGroup[]>();
const [markers, setMarkers] = useState<ErrorGroup[] | Error>();
const [ruleNames, setRuleNames] = useState<RuleDetails[]>([]);
const [isLoading, setIsLoading] = useState<boolean>(true);
const [tsVersions, setTSVersion] = useState<readonly string[]>([]);
Expand Down
30 changes: 18 additions & 12 deletions packages/website/src/components/editor/LoadedEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,21 +127,27 @@ export const LoadedEditor: React.FC<LoadedEditorProps> = ({

webLinter.updateParserOptions(jsx, sourceType);

const messages = webLinter.lint(code);
try {
const messages = webLinter.lint(code);

const markers = parseLintResults(messages, codeActions, ruleId =>
sandboxInstance.monaco.Uri.parse(webLinter.rulesUrl.get(ruleId) ?? ''),
);
const markers = parseLintResults(messages, codeActions, ruleId =>
sandboxInstance.monaco.Uri.parse(
webLinter.rulesUrl.get(ruleId) ?? '',
),
);

sandboxInstance.monaco.editor.setModelMarkers(
tabs.code,
'eslint',
markers,
);
sandboxInstance.monaco.editor.setModelMarkers(
tabs.code,
'eslint',
markers,
);

// fallback when event is not preset, ts < 4.0.5
if (!sandboxInstance.monaco.editor.onDidChangeMarkers) {
updateMarkers();
// fallback when event is not preset, ts < 4.0.5
if (!sandboxInstance.monaco.editor.onDidChangeMarkers) {
updateMarkers();
}
} catch (e) {
onMarkersChange(e as Error);
}

onEsASTChange(webLinter.storedAST);
Expand Down
2 changes: 1 addition & 1 deletion packages/website/src/components/editor/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ export interface CommonEditorProps extends ConfigModel {
readonly onTsASTChange: (value: undefined | SourceFile) => void;
readonly onEsASTChange: (value: undefined | TSESTree.Program) => void;
readonly onScopeChange: (value: undefined | Record<string, unknown>) => void;
readonly onMarkersChange: (value: ErrorGroup[]) => void;
readonly onMarkersChange: (value: ErrorGroup[] | Error) => void;
readonly onSelect: (position: Monaco.Position | null) => void;
}