Commit ae383cfd authored by Niklas Mischkulnig's avatar Niklas Mischkulnig

Include full error message in toDisplayRedbox

parent 4f5da820
...@@ -91,8 +91,7 @@ export interface ErrorSnapshot { ...@@ -91,8 +91,7 @@ export interface ErrorSnapshot {
} }
/** /**
* Focus source to just the header, errored line, and cursor. * Strips surrounding context lines from the codeframe.
* Strips surrounding context lines.
*/ */
function focusSource( function focusSource(
source: string | null, source: string | null,
...@@ -102,6 +101,7 @@ function focusSource( ...@@ -102,6 +101,7 @@ function focusSource(
let focusedSource = '' let focusedSource = ''
const sourceFrameLines = source.split('\n') const sourceFrameLines = source.split('\n')
let encounteredCursor = false
for (let i = 0; i < sourceFrameLines.length; i++) { for (let i = 0; i < sourceFrameLines.length; i++) {
const sourceFrameLine = sourceFrameLines[i].trimEnd() const sourceFrameLine = sourceFrameLines[i].trimEnd()
if (sourceFrameLine === '') { if (sourceFrameLine === '') {
...@@ -109,12 +109,18 @@ function focusSource( ...@@ -109,12 +109,18 @@ function focusSource(
} }
if (sourceFrameLine.startsWith('>')) { if (sourceFrameLine.startsWith('>')) {
if (!encounteredCursor) {
// This is where the cursor will point // This is where the cursor will point
// Include the cursor and nothing below since it's just surrounding code. // Include the cursor and nothing below since it's just surrounding code.
focusedSource += '\n' + sourceFrameLine focusedSource += '\n' + sourceFrameLine
focusedSource += '\n' + sourceFrameLines[i + 1] focusedSource += '\n' + sourceFrameLines[i + 1]
break i++ // skip the next line since we already included it as context for the errored line
encounteredCursor = true
} }
continue
}
// Include error message before or after the code frame
const isCodeFrameLine = /^ {2}\s*\d+ \|/.test(sourceFrameLine) const isCodeFrameLine = /^ {2}\s*\d+ \|/.test(sourceFrameLine)
if (!isCodeFrameLine) { if (!isCodeFrameLine) {
focusedSource += '\n' + sourceFrameLine focusedSource += '\n' + sourceFrameLine
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment