|
1 | | -import { renderHeader, renderLocation, renderSection } from "./utils"; |
| 1 | +import { renderHeader, renderLocation, renderSection, renderCustomSection } from "./utils"; |
2 | 2 | import { |
3 | 3 | ArgumentMismatchError, |
4 | 4 | InvalidRefinementError, |
@@ -37,49 +37,35 @@ export function getErrorsView(errors: LJError[], showAll: boolean, currentFile: |
37 | 37 | `; |
38 | 38 | } |
39 | 39 |
|
| 40 | +const errorContentRenderers: Partial<Record<LJError['type'], (error: LJError) => string>> = { |
| 41 | + 'refinement-error': (e: RefinementError) => /*html*/` |
| 42 | + ${renderSection('Expected', e.expected.value)} |
| 43 | + ${renderCustomSection('Found', renderDerivationNode(e, e.found))} |
| 44 | + `, |
| 45 | + 'state-refinement-error': (e: StateRefinementError) => /*html*/` |
| 46 | + ${renderSection('Expected', e.expected)} |
| 47 | + ${renderSection('Found', e.found)} |
| 48 | + `, |
| 49 | + 'invalid-refinement-error': (e: InvalidRefinementError) => /*html*/` |
| 50 | + ${renderSection('Refinement', e.refinement)} |
| 51 | + `, |
| 52 | + 'not-found-error': (e: NotFoundError) => /*html*/` |
| 53 | + ${renderSection(e.kind, e.name)} |
| 54 | + `, |
| 55 | + 'state-conflict-error': (e: StateConflictError) => /*html*/` |
| 56 | + ${renderSection('State', e.state)} |
| 57 | + `, |
| 58 | + 'syntax-error': (e: SyntaxError) => /*html*/` |
| 59 | + ${renderSection('Refinement', e.refinement)} |
| 60 | + `, |
| 61 | + 'argument-mismatch-error': (e: ArgumentMismatchError) => /*html*/` |
| 62 | + ${renderSection('Refinement', e.refinement)} |
| 63 | + ` |
| 64 | +}; |
| 65 | + |
40 | 66 | export function renderError(error: LJError): string { |
41 | 67 | const header = renderHeader(error); |
| 68 | + const content = errorContentRenderers[error.type]?.(error) ?? ''; |
42 | 69 | const location = renderLocation(error); |
43 | | - switch (error.type) { |
44 | | - case 'refinement-error': { |
45 | | - const e = error as RefinementError; |
46 | | - return /*html*/` |
47 | | - ${header} |
48 | | - ${renderSection('Expected', `<pre>${e.expected.value}</pre>`)} |
49 | | - ${renderSection('Found', renderDerivationNode(e, e.found))} |
50 | | - ${location} |
51 | | - `; |
52 | | - } |
53 | | - case 'state-refinement-error': { |
54 | | - const e = error as StateRefinementError; |
55 | | - return `${header}${renderSection('Expected', `<pre>${e.expected}</pre>`)}${renderSection('Found', `<pre>${e.found}</pre>`)}${location}`; |
56 | | - } |
57 | | - case 'invalid-refinement-error': { |
58 | | - const e = error as InvalidRefinementError; |
59 | | - return `${header}${renderSection('Refinement', `<pre>"${e.refinement}"</pre>`)}${location}`; |
60 | | - } |
61 | | - case 'not-found-error': { |
62 | | - const e = error as NotFoundError; |
63 | | - const content = `<p>${e.kind} <b>${e.name}</b> not found</p>`; |
64 | | - return `<h3>${error.title}</h3><div class="diagnostic-header">${content}</div>${location}`; |
65 | | - } |
66 | | - case 'state-conflict-error': { |
67 | | - const e = error as StateConflictError; |
68 | | - return `${header}${renderSection('State', `<pre>${e.state}</pre>`)}${location}`; |
69 | | - } |
70 | | - case 'syntax-error': { |
71 | | - const e = error as SyntaxError; |
72 | | - return `${header}${renderSection('Refinement', `<pre>"${e.refinement}"</pre>`)}${location}`; |
73 | | - } |
74 | | - case 'argument-mismatch-error': { |
75 | | - const e = error as ArgumentMismatchError; |
76 | | - return `${header}${renderSection('Refinement', `<pre>"${e.refinement}"</pre>`)}${location}`; |
77 | | - } |
78 | | - default: |
79 | | - return `${header}${location}`; |
80 | | - } |
81 | | -} |
82 | | -function renderToggleButton(showAll: boolean) { |
83 | | - throw new Error("Function not implemented."); |
| 70 | + return /*html*/`${header}${content}${location}`; |
84 | 71 | } |
85 | | - |
0 commit comments