SetHelp marks the "last error" field in the lexer to become a help text. This method is invoked in the error action of the parser, so the help text is only produced if the last token encountered was HELPTOKEN -- other cases are just syntax errors, and in that case we do not want the help text to ove
(msg HelpMessage)
| 470 | // lastError field, which was set earlier to contain details about the |
| 471 | // syntax error. |
| 472 | func (l *lexer) SetHelp(msg HelpMessage) { |
| 473 | if l.lastError == nil { |
| 474 | l.lastError = pgerror.WithCandidateCode(errors.New("help request"), pgcode.Syntax) |
| 475 | } |
| 476 | |
| 477 | if lastTok := l.lastToken(); lastTok.id == HELPTOKEN { |
| 478 | l.populateHelpMsg(msg.String()) |
| 479 | } else { |
| 480 | if msg.Command != "" { |
| 481 | l.lastError = errors.WithHintf(l.lastError, `try \h %s`, msg.Command) |
| 482 | } else { |
| 483 | l.lastError = errors.WithHintf(l.lastError, `try \hf %s`, msg.Function) |
| 484 | } |
| 485 | } |
| 486 | } |
| 487 | |
| 488 | // specialHelpErrorPrefix is a special prefix that must be present at |
| 489 | // the start of an error message to be considered a valid help |
no test coverage detected