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)
| 237 | // lastError field, which was set earlier to contain details about the |
| 238 | // syntax error. |
| 239 | func (l *lexer) SetHelp(msg HelpMessage) { |
| 240 | if l.lastError == nil { |
| 241 | l.lastError = pgerror.WithCandidateCode(errors.New("help request"), pgcode.Syntax) |
| 242 | } |
| 243 | |
| 244 | if lastTok := l.lastToken(); lastTok.id == HELPTOKEN { |
| 245 | l.populateHelpMsg(msg.String()) |
| 246 | } else { |
| 247 | if msg.Command != "" { |
| 248 | l.lastError = errors.WithHintf(l.lastError, `try \h %s`, msg.Command) |
| 249 | } else { |
| 250 | l.lastError = errors.WithHintf(l.lastError, `try \hf %s`, msg.Function) |
| 251 | } |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | func (l *lexer) populateHelpMsg(msg string) { |
| 256 | l.lastError = errors.WithHint(errors.Wrap(l.lastError, "help token in input"), msg) |
no test coverage detected