Change error handling to print message before exiting script (error description will appear in error tab)
This commit is contained in:
parent
669f8875aa
commit
4973b245ad
@ -1,7 +1,7 @@
|
||||
#/bin/bash
|
||||
|
||||
# Font
|
||||
swift run -c release FontToolCore "./Fonts/sampleFontsAll.txt" \
|
||||
swift run -c release FontToolCore "./Fonts/sampleFontsAl.txt" \
|
||||
--extension-output-path "./Fonts/Generated" \
|
||||
--extension-name "R2Font" \
|
||||
--extension-suffix "GenAllScript"
|
||||
|
@ -17,37 +17,19 @@ enum ColorToolError: Error {
|
||||
var description: String {
|
||||
switch self {
|
||||
case .badFormat(let info):
|
||||
return """
|
||||
[ColorTool]
|
||||
Bad line format: \(info). Accepted format are:
|
||||
- colorName="#RGB/#ARGB"
|
||||
- colorName "#RGB/#ARGB"
|
||||
- colorName "#RGB/#ARGB" "#RGB/#ARGB"
|
||||
"""
|
||||
return "error:[ColorTool] Bad line format: \(info). Accepted format are: colorName=\"#RGB/#ARGB\"; colorName \"#RGB/#ARGB\"; colorName \"#RGB/#ARGB\" \"#RGB/#ARGB\""
|
||||
|
||||
case .writeAsset(let info):
|
||||
return """
|
||||
[ColorTool]
|
||||
An error occured while writing color in Xcasset: \(info)
|
||||
"""
|
||||
return "error:[ColorTool] An error occured while writing color in Xcasset: \(info)"
|
||||
|
||||
case .writeExtension(let filename, let info):
|
||||
return """
|
||||
[ColorTool]
|
||||
An error occured while writing extension in \(filename): \(info)
|
||||
"""
|
||||
return "error:[ColorTool] An error occured while writing extension in \(filename): \(info)"
|
||||
|
||||
case .fileNotExists(let filename):
|
||||
return """
|
||||
[ColorTool]
|
||||
File \(filename) does not exists
|
||||
"""
|
||||
return "error:[ColorTool] File \(filename) does not exists"
|
||||
|
||||
case .badColorDefinition(let lightColor, let darkColor):
|
||||
return """
|
||||
[ColorTool]
|
||||
One of these two colors has invalid synthax: -\(lightColor)- or -\(darkColor)-
|
||||
"""
|
||||
return "error:[ColorTool]One of these two colors has invalid synthax: -\(lightColor)- or -\(darkColor)-"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,9 @@ struct ColorXcassetHelper {
|
||||
do {
|
||||
try color.contentsJSON().write(to: contentsJsonPathURL, atomically: true, encoding: .utf8)
|
||||
} catch (let error) {
|
||||
ColorTool.exit(withError: ColorToolError.writeAsset(error.localizedDescription))
|
||||
let error = ColorToolError.writeAsset(error.localizedDescription)
|
||||
print(error.localizedDescription)
|
||||
ColorTool.exit(withError: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,9 @@ struct GenColor {
|
||||
}
|
||||
|
||||
guard allComponents.contains(true) == false else {
|
||||
ColorTool.exit(withError: ColorToolError.badColorDefinition(light, dark))
|
||||
let error = ColorToolError.badColorDefinition(light, dark)
|
||||
print(error.localizedDescription)
|
||||
ColorTool.exit(withError: error)
|
||||
}
|
||||
|
||||
return """
|
||||
|
@ -52,10 +52,14 @@ struct ColorTool: ParsableCommand {
|
||||
// Check requirements
|
||||
let fileManager = FileManager()
|
||||
guard fileManager.fileExists(atPath: xcassetsPath) else {
|
||||
ColorTool.exit(withError: ColorToolError.fileNotExists(xcassetsPath))
|
||||
let error = ColorToolError.fileNotExists(xcassetsPath)
|
||||
print(error.localizedDescription)
|
||||
ColorTool.exit(withError: error)
|
||||
}
|
||||
guard fileManager.fileExists(atPath: inputFile) else {
|
||||
ColorTool.exit(withError: ColorToolError.fileNotExists(xcassetsPath))
|
||||
let error = ColorToolError.fileNotExists(inputFile)
|
||||
print(error.localizedDescription)
|
||||
ColorTool.exit(withError: error)
|
||||
}
|
||||
|
||||
// Check if needed to regenerate
|
||||
@ -103,7 +107,9 @@ struct ColorTool: ParsableCommand {
|
||||
do {
|
||||
try extensionContent.write(to: extensionFilePathURL, atomically: true, encoding: .utf8)
|
||||
} catch (let error) {
|
||||
ColorTool.exit(withError: ColorToolError.writeExtension(extensionFilePath, error.localizedDescription))
|
||||
let error = ColorToolError.writeExtension(extensionFilePath, error.localizedDescription)
|
||||
print(error.localizedDescription)
|
||||
ColorTool.exit(withError: error)
|
||||
}
|
||||
}
|
||||
|
||||
@ -128,7 +134,9 @@ struct ColorTool: ParsableCommand {
|
||||
let colorContent = colorLineCleanedUp.split(separator: " ")
|
||||
|
||||
guard colorContent.count >= 2 else {
|
||||
ColorTool.exit(withError: ColorToolError.badFormat(colorLine))
|
||||
let error = ColorToolError.badFormat(colorLine)
|
||||
print(error.localizedDescription)
|
||||
ColorTool.exit(withError: error)
|
||||
}
|
||||
|
||||
switch colorStyle {
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user