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)
| 261 | // lastError field, which was set earlier to contain details about the |
| 262 | // syntax error. |
| 263 | func (l *lexer) SetHelp(msg HelpMessage) { |
| 264 | if l.lastError == nil { |
| 265 | l.lastError = pgerror.WithCandidateCode(errors.New("help request"), pgcode.Syntax) |
| 266 | } |
| 267 | |
| 268 | if lastTok := l.lastToken(); lastTok.id == HELPTOKEN { |
| 269 | l.populateHelpMsg(msg.String()) |
| 270 | } else { |
| 271 | if msg.Command != "" { |
| 272 | l.lastError = errors.WithHintf(l.lastError, `try \h %s`, msg.Command) |
| 273 | } else { |
| 274 | l.lastError = errors.WithHintf(l.lastError, `try \hf %s`, msg.Function) |
| 275 | } |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | func (l *lexer) populateHelpMsg(msg string) { |
| 280 | l.lastError = errors.WithHint(errors.Wrap(l.lastError, "help token in input"), msg) |
no test coverage detected