GenerateManualPluginError.swift 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // This source file is part of the Swift Argument Parser open source project
  4. //
  5. // Copyright (c) 2021 Apple Inc. and the Swift project authors
  6. // Licensed under Apache License v2.0 with Runtime Library Exception
  7. //
  8. // See https://swift.org/LICENSE.txt for license information
  9. //
  10. //===----------------------------------------------------------------------===//
  11. import Foundation
  12. import PackagePlugin
  13. enum GenerateManualPluginError: Error {
  14. case unknownBuildConfiguration(String)
  15. case buildFailed(String)
  16. case createOutputDirectoryFailed(Error)
  17. case subprocessFailedNonZeroExit(Path, Int32)
  18. case subprocessFailedError(Path, Error)
  19. }
  20. extension GenerateManualPluginError: CustomStringConvertible {
  21. var description: String {
  22. switch self {
  23. case .unknownBuildConfiguration(let configuration):
  24. return "Build failed: Unknown build configuration '\(configuration)'."
  25. case .buildFailed(let logText):
  26. return "Build failed: \(logText)."
  27. case .createOutputDirectoryFailed(let error):
  28. return """
  29. Failed to create output directory: '\(error.localizedDescription)'
  30. """
  31. case .subprocessFailedNonZeroExit(let tool, let exitCode):
  32. return """
  33. '\(tool.lastComponent)' invocation failed with a nonzero exit code: \
  34. '\(exitCode)'.
  35. """
  36. case .subprocessFailedError(let tool, let error):
  37. return """
  38. '\(tool.lastComponent)' invocation failed: \
  39. '\(error.localizedDescription)'
  40. """
  41. }
  42. }
  43. }
  44. extension GenerateManualPluginError: LocalizedError {
  45. var errorDescription: String? { self.description }
  46. }