From dfa6cc7c4212cd922439e14f9269878f182e0c83 Mon Sep 17 00:00:00 2001 From: Yi Wang Date: Tue, 14 May 2019 13:45:30 -0700 Subject: [PATCH] Replace all fatalError with error logging (#295) * Replace all fatalError with error logging * Fix default error param --- .../Generating/DependencyGraphExporter.swift | 2 +- .../Pluginized/PluginizedDependencyGraphExporter.swift | 2 +- .../Parsing/AbstractDependencyGraphParser.swift | 4 ++-- .../Parsing/DependencyGraphParser.swift | 2 +- .../Pluginized/PluginizedDependencyGraphParser.swift | 2 +- Generator/Sources/needle/GenerateCommand.swift | 10 +++++----- .../Sources/needle/PrintDependencyTreeCommand.swift | 8 ++++---- Generator/Sources/needle/main.swift | 5 +++-- 8 files changed, 18 insertions(+), 17 deletions(-) diff --git a/Generator/Sources/NeedleFramework/Generating/DependencyGraphExporter.swift b/Generator/Sources/NeedleFramework/Generating/DependencyGraphExporter.swift index 48ef9718..d8f30904 100644 --- a/Generator/Sources/NeedleFramework/Generating/DependencyGraphExporter.swift +++ b/Generator/Sources/NeedleFramework/Generating/DependencyGraphExporter.swift @@ -83,7 +83,7 @@ class DependencyGraphExporter { } else if currentTask is DependencyProviderSerializerTask, let serializedProviders = currentResult as? [SerializedProvider] { return .endOfSequence(serializedProviders) } else { - fatalError("Unhandled task \(currentTask) with result \(currentResult)") + error("Unhandled task \(currentTask) with result \(currentResult)") } } taskHandleTuples.append((taskHandle, component.name)) diff --git a/Generator/Sources/NeedleFramework/Generating/Pluginized/PluginizedDependencyGraphExporter.swift b/Generator/Sources/NeedleFramework/Generating/Pluginized/PluginizedDependencyGraphExporter.swift index cf5c47e5..5ed38072 100644 --- a/Generator/Sources/NeedleFramework/Generating/Pluginized/PluginizedDependencyGraphExporter.swift +++ b/Generator/Sources/NeedleFramework/Generating/Pluginized/PluginizedDependencyGraphExporter.swift @@ -88,7 +88,7 @@ class PluginizedDependencyGraphExporter { } else if currentTask is PluginizedDependencyProviderSerializerTask, let serializedProviders = currentResult as? [SerializedProvider] { return .endOfSequence(serializedProviders) } else { - fatalError("Unhandled task \(currentTask) with result \(currentResult)") + error("Unhandled task \(currentTask) with result \(currentResult)") } } taskHandleTuples.append((taskHandle, component.name)) diff --git a/Generator/Sources/NeedleFramework/Parsing/AbstractDependencyGraphParser.swift b/Generator/Sources/NeedleFramework/Parsing/AbstractDependencyGraphParser.swift index 10ab9b46..1e6b80f1 100644 --- a/Generator/Sources/NeedleFramework/Parsing/AbstractDependencyGraphParser.swift +++ b/Generator/Sources/NeedleFramework/Parsing/AbstractDependencyGraphParser.swift @@ -108,7 +108,7 @@ class AbstractDependencyGraphParser { } else if currentTask is ComponentExtensionsParserTask, let node = currentResult as? ComponentExtensionNode { return .endOfSequence(node) } else { - fatalError("Unhandled task \(currentTask) with result \(currentResult)") + error("Unhandled task \(currentTask) with result \(currentResult)") } } } @@ -174,7 +174,7 @@ class AbstractDependencyGraphParser { return .endOfSequence(nil) } } else { - fatalError("Unhandled task \(currentTask) with result \(currentResult)") + error("Unhandled task \(currentTask) with result \(currentResult)") } } } diff --git a/Generator/Sources/NeedleFramework/Parsing/DependencyGraphParser.swift b/Generator/Sources/NeedleFramework/Parsing/DependencyGraphParser.swift index e78c77bb..d6bca874 100644 --- a/Generator/Sources/NeedleFramework/Parsing/DependencyGraphParser.swift +++ b/Generator/Sources/NeedleFramework/Parsing/DependencyGraphParser.swift @@ -86,7 +86,7 @@ class DependencyGraphParser: AbstractDependencyGraphParser { } else if currentTask is DeclarationsParserTask, let node = currentResult as? DependencyGraphNode { return .endOfSequence(node) } else { - fatalError("Unhandled task \(currentTask) with result \(currentResult)") + error("Unhandled task \(currentTask) with result \(currentResult)") } } diff --git a/Generator/Sources/NeedleFramework/Parsing/Pluginized/PluginizedDependencyGraphParser.swift b/Generator/Sources/NeedleFramework/Parsing/Pluginized/PluginizedDependencyGraphParser.swift index 7c5998d0..1394d991 100644 --- a/Generator/Sources/NeedleFramework/Parsing/Pluginized/PluginizedDependencyGraphParser.swift +++ b/Generator/Sources/NeedleFramework/Parsing/Pluginized/PluginizedDependencyGraphParser.swift @@ -86,7 +86,7 @@ class PluginizedDependencyGraphParser: AbstractDependencyGraphParser { } else if currentTask is PluginizedDeclarationsParserTask, let node = currentResult as? PluginizedDependencyGraphNode { return .endOfSequence(node) } else { - fatalError("Unhandled task \(currentTask) with result \(currentResult)") + error("Unhandled task \(currentTask) with result \(currentResult)") } } diff --git a/Generator/Sources/needle/GenerateCommand.swift b/Generator/Sources/needle/GenerateCommand.swift index 8ebf0b40..8dae4267 100644 --- a/Generator/Sources/needle/GenerateCommand.swift +++ b/Generator/Sources/needle/GenerateCommand.swift @@ -81,15 +81,15 @@ class GenerateCommand: AbstractCommand { do { try generator.generate(from: sourceRootPaths, withSourcesListFormat: sourcesListFormat, excludingFilesEndingWith: excludeSuffixes, excludingFilesWithPaths: excludePaths, with: additionalImports, headerDocPath, to: destinationPath, shouldCollectParsingInfo: shouldCollectParsingInfo, parsingTimeout: parsingTimeout, exportingTimeout: exportingTimeout, retryParsingOnTimeoutLimit: retryParsingOnTimeoutLimit, concurrencyLimit: concurrencyLimit) } catch GenericError.withMessage(let message) { - fatalError(message) - } catch { - fatalError("Unknown error: \(error)") + error(message) + } catch (let e) { + error("Unknown error: \(e)") } } else { - fatalError("Missing source files root directories.") + error("Missing source files root directories.") } } else { - fatalError("Missing destination path.") + error("Missing destination path.") } } diff --git a/Generator/Sources/needle/PrintDependencyTreeCommand.swift b/Generator/Sources/needle/PrintDependencyTreeCommand.swift index f7eb42b2..0ee4f2b6 100644 --- a/Generator/Sources/needle/PrintDependencyTreeCommand.swift +++ b/Generator/Sources/needle/PrintDependencyTreeCommand.swift @@ -67,12 +67,12 @@ class PrintDependencyTreeCommand: AbstractCommand { do { try generator.printDependencyTree(from: sourceRootPaths, withSourcesListFormat: sourcesListFormat, excludingFilesEndingWith: excludeSuffixes, excludingFilesWithPaths: excludePaths, shouldCollectParsingInfo: shouldCollectParsingInfo, parsingTimeout: parsingTimeout, retryParsingOnTimeoutLimit: retryParsingOnTimeoutLimit, concurrencyLimit: concurrencyLimit, rootComponentName: rootComponentName) } catch GenericError.withMessage(let message) { - fatalError(message) - } catch { - fatalError("Unknown error: \(error)") + error(message) + } catch (let e) { + error("Unknown error: \(e)") } } else { - fatalError("Missing source files root directories.") + error("Missing source files root directories.") } } diff --git a/Generator/Sources/needle/main.swift b/Generator/Sources/needle/main.swift index 15c78502..92b9cf53 100644 --- a/Generator/Sources/needle/main.swift +++ b/Generator/Sources/needle/main.swift @@ -18,6 +18,7 @@ import Basic import CommandFramework import Foundation import NeedleFramework +import SourceParsingFramework import SPMUtility func main() { @@ -27,8 +28,8 @@ func main() { do { let args = try parser.parse(inputs) execute(commands, with: parser, args) - } catch { - fatalError("Command-line pasing error (use --help for help): \(error)") + } catch (let e) { + error("Command-line pasing error (use --help for help): \(e)") } }