error_builders.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #ifndef CARBON_EXPLORER_COMMON_ERROR_BUILDERS_H_
  5. #define CARBON_EXPLORER_COMMON_ERROR_BUILDERS_H_
  6. #include "common/error.h"
  7. #include "explorer/common/source_location.h"
  8. namespace Carbon {
  9. // Builds an Error instance with the specified message. This should be used for
  10. // non-recoverable errors with user input.
  11. //
  12. // For example:
  13. // return ProgramError(line_num) << "Line is bad!";
  14. // return ProgramError() << "Application is bad!";
  15. //
  16. // Where possible, try to identify the error as a compilation or runtime error.
  17. // Use CHECK/FATAL for internal errors. The generic program error option is
  18. // provided as a fallback for cases that don't fit those classifications.
  19. inline auto CompilationError(SourceLocation loc) -> ErrorBuilder {
  20. return ErrorBuilder("COMPILATION ERROR", loc.ToString());
  21. }
  22. inline auto ProgramError(SourceLocation loc) -> ErrorBuilder {
  23. return ErrorBuilder("PROGRAM ERROR", loc.ToString());
  24. }
  25. inline auto RuntimeError(SourceLocation loc) -> ErrorBuilder {
  26. return ErrorBuilder("RUNTIME ERROR", loc.ToString());
  27. }
  28. } // namespace Carbon
  29. #endif // CARBON_EXPLORER_COMMON_ERROR_BUILDERS_H_