MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / SetHelp

Method SetHelp

pkg/sql/parser/lexer.go:472–486  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

470// lastError field, which was set earlier to contain details about the
471// syntax error.
472func (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

Callers 2

helpWithFunction · 0.80
helpWithFunctionFunction · 0.80

Calls 4

lastTokenMethod · 0.95
populateHelpMsgMethod · 0.95
WithCandidateCodeFunction · 0.92
StringMethod · 0.65

Tested by

no test coverage detected