func (p *Parser) duplicateNameMessage(dupeError *mojom.DuplicateNameError, nameToken lexer.Token) string { if dupeError == nil { return "" } if dupeError.ExistingType() != nil { return fmt.Sprintf("%s:%s. Duplicate definition for name '%s'. "+ "The fully-qualified name of this type would be the same as "+ "an existing type definition: "+ "%s %s in %s.", p.mojomFile.FileName, nameToken.ShortLocationString(), nameToken.Text, dupeError.ExistingType().Kind(), dupeError.ExistingType().FullyQualifiedName(), dupeError.ExistingType().Scope()) } else { return fmt.Sprintf("%s:%s. Duplicate definition for name '%s'. "+ "The fully-qualified name of this value would be the same as "+ "an existing value definition: "+ "%s %s in %s.", p.mojomFile.FileName, nameToken.ShortLocationString(), nameToken.Text, dupeError.ExistingValue().Kind(), dupeError.ExistingValue().FullyQualifiedName(), dupeError.ExistingValue().Scope()) } }
// UserErrorMessageP is responsible for formatting user-facing error messages // This function is similar to UserErrorMessage except that it also allows the // caller to specify the message prefix. // prefix: An error message prefix such as "Error:". It should not end with a space. func UserErrorMessageP(file *MojomFile, token lexer.Token, prefix, message string) string { // TODO(rudominer) Allow users to disable the use of color in snippets. useColor := true // Optionally color the prefix red. if useColor && len(prefix) > 0 { prefix = fmt.Sprintf("\x1b[31;1m%s\x1b[0m", prefix) } if len(prefix) > 0 { prefix = fmt.Sprintf("%s ", prefix) } message = fmt.Sprintf("%s%s", prefix, message) filePath := "Unknown file" importedFromMessage := "" snippet := "" if file != nil { if len(file.fileContents) > 0 { snippet = fmt.Sprintf("\n%s", token.Snippet(file.fileContents, useColor)) } filePath = RelPathIfShorter(file.CanonicalFileName) importedFromMessage = file.ImportedFromMessage() } return fmt.Sprintf("\n%s:%s: %s%s\n%s", filePath, token.ShortLocationString(), message, snippet, importedFromMessage) }
func (p *Parser) newInvalidOrdinalError(objectType, objectName string, nameToken lexer.Token, err error) *ParseError { message := fmt.Sprintf("%s:%s %s %q: %s", p.mojomFile.CanonicalFileName, nameToken.ShortLocationString(), objectType, objectName, err.Error()) return &ParseError{ParserErrorCodeBadOrdinal, message} }