CommandPluginError.swift 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright 2025, gRPC Authors All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. enum CommandPluginError: Error {
  17. case invalidArgumentValue(name: String, value: String)
  18. case missingInputFile
  19. case unknownOption(String)
  20. case unknownAccessLevel(String)
  21. case unknownFileNamingStrategy(String)
  22. case conflictingFlags(String, String)
  23. case generationFailure(
  24. errorDescription: String,
  25. executable: String,
  26. arguments: [String],
  27. stdErr: String?
  28. )
  29. case tooManyParameterSeparators
  30. }
  31. extension CommandPluginError: CustomStringConvertible {
  32. var description: String {
  33. switch self {
  34. case .invalidArgumentValue(let name, let value):
  35. return "Invalid value '\(value)', for '\(name)'."
  36. case .missingInputFile:
  37. return "No input file(s) specified."
  38. case .unknownOption(let name):
  39. return "Provided option is unknown: \(name)."
  40. case .unknownAccessLevel(let value):
  41. return "Provided access level is unknown: \(value)."
  42. case .unknownFileNamingStrategy(let value):
  43. return "Provided file naming strategy is unknown: \(value)."
  44. case .conflictingFlags(let flag1, let flag2):
  45. return "Provided flags conflict: '\(flag1)' and '\(flag2)'."
  46. case .generationFailure(let errorDescription, let executable, let arguments, let stdErr):
  47. var message = """
  48. Code generation failed with: \(errorDescription).
  49. \tExecutable: \(executable)
  50. \tArguments: \(arguments.joined(separator: " "))
  51. """
  52. if let stdErr {
  53. message += """
  54. \n\tprotoc error output:
  55. \t\(stdErr)
  56. """
  57. }
  58. return message
  59. case .tooManyParameterSeparators:
  60. return "Unexpected parameter structure, too many '--' separators."
  61. }
  62. }
  63. }