From 914202b269d7f766a1650dd729c862aeac07de29 Mon Sep 17 00:00:00 2001 From: Roi Date: Tue, 16 Oct 2018 14:58:35 +0200 Subject: [PATCH 1/4] Avoid crash unwrapping optional date fields --- Sources/parseRows.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sources/parseRows.swift b/Sources/parseRows.swift index 2e6c527..3ee2410 100644 --- a/Sources/parseRows.swift +++ b/Sources/parseRows.swift @@ -61,7 +61,9 @@ extension PostgresStORM { let output = result.getFieldString(tupleIndex: x, fieldIndex: f) let formatter = DateFormatter() formatter.dateFormat = "yyyy/MM/dd hh:mm Z" - params[result.fieldName(index: f)!] = formatter.date(from: output!) + if let output = output { + params[result.fieldName(index: f)!] = formatter.date(from: output) + } // time // timestamp From d147f9408397a4db9ac11b18dcf9c19f3ac3f241 Mon Sep 17 00:00:00 2001 From: Roi Date: Thu, 18 Oct 2018 11:53:47 +0200 Subject: [PATCH 2/4] Do not log error messages if no error occurred --- Sources/PostgresStORM.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/PostgresStORM.swift b/Sources/PostgresStORM.swift index 149915f..38eebe9 100644 --- a/Sources/PostgresStORM.swift +++ b/Sources/PostgresStORM.swift @@ -73,9 +73,9 @@ open class PostgresStORM: StORM, StORMProtocol { let result = thisConnection.server.exec(statement: statement, params: params) // set exec message - errorMsg = thisConnection.server.errorMessage().trimmingCharacters(in: .whitespacesAndNewlines) - if StORMdebug { LogFile.info("Error msg: \(errorMsg)", logFile: "./StORMlog.txt") } if isError() { + errorMsg = thisConnection.server.errorMessage().trimmingCharacters(in: .whitespacesAndNewlines) + if StORMdebug { LogFile.info("Error msg: \(errorMsg)", logFile: "./StORMlog.txt") } thisConnection.server.close() throw StORMError.error(errorMsg) } From bf64f698c10493f1900949a8b3aba28d877ce868 Mon Sep 17 00:00:00 2001 From: Roi Date: Tue, 20 Nov 2018 10:48:04 +0100 Subject: [PATCH 3/4] Read error message before checking if there's an error --- Sources/PostgresStORM.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/PostgresStORM.swift b/Sources/PostgresStORM.swift index 38eebe9..9b6f989 100644 --- a/Sources/PostgresStORM.swift +++ b/Sources/PostgresStORM.swift @@ -73,8 +73,8 @@ open class PostgresStORM: StORM, StORMProtocol { let result = thisConnection.server.exec(statement: statement, params: params) // set exec message + errorMsg = thisConnection.server.errorMessage().trimmingCharacters(in: .whitespacesAndNewlines) if isError() { - errorMsg = thisConnection.server.errorMessage().trimmingCharacters(in: .whitespacesAndNewlines) if StORMdebug { LogFile.info("Error msg: \(errorMsg)", logFile: "./StORMlog.txt") } thisConnection.server.close() throw StORMError.error(errorMsg) From b8dd7b49818797b0d9485b5cc3ad512ddb85bcff Mon Sep 17 00:00:00 2001 From: Roi Date: Tue, 20 Nov 2018 10:49:28 +0100 Subject: [PATCH 4/4] Just show the error message if there's really an error --- Sources/PostgresStORM.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/PostgresStORM.swift b/Sources/PostgresStORM.swift index 9b6f989..8cd8479 100644 --- a/Sources/PostgresStORM.swift +++ b/Sources/PostgresStORM.swift @@ -107,8 +107,8 @@ open class PostgresStORM: StORM, StORMProtocol { // set exec message errorMsg = thisConnection.server.errorMessage().trimmingCharacters(in: .whitespacesAndNewlines) - if StORMdebug { LogFile.info("Error msg: \(errorMsg)", logFile: "./StORMlog.txt") } if isError() { + if StORMdebug { LogFile.info("Error msg: \(errorMsg)", logFile: "./StORMlog.txt") } thisConnection.server.close() throw StORMError.error(errorMsg) }