Skip to content

Commit 53afef8

Browse files
authored
Merge pull request #346 from oasisprotocol/lw/fix-validation
Fix highlighted error logs offset and hide yaml errors in machine logs
2 parents 7dac9a7 + fe1b0de commit 53afef8

2 files changed

Lines changed: 23 additions & 19 deletions

File tree

.changelog/346.feature.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Highlight errors in logs

src/components/CodeDisplay/index.tsx

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,16 @@ export const CodeDisplay: FC<CodeDisplayProps> = ({ data, className, readOnly =
6262
})
6363
}
6464

65-
const highlightErrorLogs = () => {
65+
const highlightErrorLogs = (newData: string | undefined) => {
6666
const monacoInstance = monacoInstanceRef.current
67-
if (!monacoInstance || !editorRef.current || data === undefined) {
67+
if (!monacoInstance || !editorRef.current || newData === undefined) {
6868
return
6969
}
7070
const model = editorRef.current.getModel()
7171
if (!model) return
7272

7373
const markers: monaco.editor.IMarkerData[] = []
74-
for (const [i, line] of data.split('\n').entries()) {
74+
for (const [i, line] of newData.split('\n').entries()) {
7575
if (
7676
line.includes('"err"') ||
7777
line.toLowerCase().includes('error') ||
@@ -91,28 +91,18 @@ export const CodeDisplay: FC<CodeDisplayProps> = ({ data, className, readOnly =
9191
monacoInstance.editor.setModelMarkers(model, 'highlightErrorLogs', markers)
9292
}
9393

94-
const handleEditorDidMount = (
95-
editor: monaco.editor.IStandaloneCodeEditor,
96-
monacoInstance: typeof monaco,
97-
) => {
98-
editorRef.current = editor
99-
monacoInstanceRef.current = monacoInstance
100-
highlightErrorLogs()
101-
}
102-
103-
const handleEditorChange = (value: string | undefined) => {
94+
const highlightYamlErrors = (newData: string | undefined) => {
10495
const monacoInstance = monacoInstanceRef.current
105-
if (!monacoInstance || !editorRef.current || value === undefined) {
96+
if (!monacoInstance || !editorRef.current || newData === undefined) {
10697
return
10798
}
108-
10999
const model = editorRef.current.getModel()
110100
if (!model) return
111101

112102
const markers: monaco.editor.IMarkerData[] = []
113103

114104
try {
115-
yaml.parse(value)
105+
yaml.parse(newData)
116106
} catch (e) {
117107
const yamlError = e as { message: string; linePos: { line: number; col: number }[] }
118108
if (yamlError.linePos && yamlError.linePos.length > 0) {
@@ -129,11 +119,24 @@ export const CodeDisplay: FC<CodeDisplayProps> = ({ data, className, readOnly =
129119
}
130120
}
131121

132-
monacoInstance.editor.setModelMarkers(model, 'yaml-validator', markers)
122+
monacoInstance.editor.setModelMarkers(model, 'highlightYamlErrors', markers)
123+
}
124+
125+
const handleEditorDidMount = (
126+
editor: monaco.editor.IStandaloneCodeEditor,
127+
monacoInstance: typeof monaco,
128+
) => {
129+
editorRef.current = editor
130+
monacoInstanceRef.current = monacoInstance
131+
highlightErrorLogs(data)
132+
}
133+
134+
const handleEditorChange = (newData: string | undefined) => {
135+
if (!readOnly) highlightYamlErrors(newData)
133136

134-
highlightErrorLogs()
137+
highlightErrorLogs(newData)
135138

136-
onChange?.(value)
139+
onChange?.(newData)
137140
}
138141

139142
return (

0 commit comments

Comments
 (0)