Change error handling to print message before exiting script (error description will appear in error tab)
This commit is contained in:
@ -13,26 +13,16 @@ enum FontToolError: Error {
|
||||
case inputFolderNotFound(String)
|
||||
case fileNotExists(String)
|
||||
|
||||
var description: String {
|
||||
var localizedDescription: String {
|
||||
switch self {
|
||||
case .fcScan(let path, let code, let output):
|
||||
return """
|
||||
error: [FontTool]
|
||||
Error while getting fontName (fc-scan --format %{postscriptname} \(path).
|
||||
fc-scan exit with \(code) and output is: \(output ?? "no output")
|
||||
"""
|
||||
return "error:[FontTool] Error while getting fontName (fc-scan --format %{postscriptname} \(path). fc-scan exit with \(code) and output is: \(output ?? "no output")"
|
||||
|
||||
case .inputFolderNotFound(let inputFolder):
|
||||
return """
|
||||
error: [FontTool]
|
||||
Input folder not found: \(inputFolder)
|
||||
"""
|
||||
return " error:[FontTool] Input folder not found: \(inputFolder)"
|
||||
|
||||
case .fileNotExists(let filename):
|
||||
return """
|
||||
error: [FontTool]
|
||||
File \(filename) does not exists
|
||||
"""
|
||||
return " error:[FontTool] File \(filename) does not exists "
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,9 @@ class FontToolHelper {
|
||||
// Get a enumerator for all files
|
||||
let fileManager = FileManager()
|
||||
guard fileManager.fileExists(atPath: inputFolder) else {
|
||||
FontTool.exit(withError: FontToolError.inputFolderNotFound(inputFolder))
|
||||
let error = FontToolError.inputFolderNotFound(inputFolder)
|
||||
print(error.localizedDescription)
|
||||
FontTool.exit(withError: error)
|
||||
}
|
||||
|
||||
let enumerator: FileManager.DirectoryEnumerator = fileManager.enumerator(atPath: inputFolder)!
|
||||
@ -41,7 +43,9 @@ class FontToolHelper {
|
||||
let task = Shell.shell("fc-scan", "--format", "%{postscriptname}", path)
|
||||
|
||||
guard let fontName = task.output, task.terminationStatus == 0 else {
|
||||
FontTool.exit(withError: FontToolError.fcScan(path, task.terminationStatus, task.output))
|
||||
let error = FontToolError.fcScan(path, task.terminationStatus, task.output)
|
||||
print(error.localizedDescription)
|
||||
FontTool.exit(withError: error)
|
||||
}
|
||||
|
||||
return fontName
|
||||
|
@ -41,7 +41,9 @@ struct FontTool: ParsableCommand {
|
||||
// Check requirements
|
||||
let fileManager = FileManager()
|
||||
guard fileManager.fileExists(atPath: inputFile) else {
|
||||
FontTool.exit(withError: FontToolError.fileNotExists(inputFile))
|
||||
let error = FontToolError.fileNotExists(inputFile)
|
||||
print(error.localizedDescription)
|
||||
FontTool.exit(withError: error)
|
||||
}
|
||||
|
||||
// Check if needed to regenerate
|
||||
|
Reference in New Issue
Block a user