MCPcopy
hub / github.com/parinfer/parinfer.js / createError

Function createError

parinfer.js:560–615  ·  view source on GitHub ↗
(result, name)

Source from the content-addressed store, hash-verified

558 }
559
560 function createError (result, name) {
561 const cache = result.errorPosCache[name]
562
563 let keyLineNo = 'inputLineNo'
564 let keyX = 'inputX'
565 if (result.partialResult) {
566 keyLineNo = 'lineNo'
567 keyX = 'x'
568 }
569
570 let lineNo = 0
571 let x = 0
572 if (cache) {
573 lineNo = cache[keyLineNo]
574 x = cache[keyX]
575 } else {
576 lineNo = result[keyLineNo]
577 x = result[keyX]
578 }
579
580 const err = {
581 parinferError: true,
582 name: name,
583 message: errorMessages[name],
584 lineNo: lineNo,
585 x: x
586 }
587 const opener = peek(result.parenStack, 0)
588
589 if (name === ERROR_UNMATCHED_CLOSE_PAREN) {
590 // extra error info for locating the open-paren that it should've matched
591 const cache2 = result.errorPosCache[ERROR_UNMATCHED_OPEN_PAREN]
592 if (cache2 || opener) {
593 let lineNo2 = 0
594 let x2 = 0
595 if (cache2) {
596 lineNo2 = cache2[keyLineNo]
597 x2 = cache2[keyX]
598 } else {
599 lineNo2 = opener[keyLineNo]
600 x2 = opener[keyX]
601 }
602
603 err.extra = {
604 name: ERROR_UNMATCHED_OPEN_PAREN,
605 lineNo: lineNo2,
606 x: x2
607 }
608 }
609 } else if (name === ERROR_UNCLOSED_PAREN) {
610 err.lineNo = opener[keyLineNo]
611 err.x = opener[keyX]
612 }
613
614 return err
615 }
616
617 // ---------------------------------------------------------------------------

Callers 7

onUnmatchedCloseParenFunction · 0.85
afterBackslashFunction · 0.85
onIndentFunction · 0.85
checkLeadingCloseParenFunction · 0.85
onLeadingCloseParenFunction · 0.85
finalizeResultFunction · 0.85

Calls 1

peekFunction · 0.85

Tested by

no test coverage detected