Skip to content

Fatal error using try! #430

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Silve2611 opened this issue May 12, 2016 · 5 comments
Closed

Fatal error using try! #430

Silve2611 opened this issue May 12, 2016 · 5 comments
Milestone

Comments

@Silve2611
Copy link

Silve2611 commented May 12, 2016

As already mentioned in #339 the try! will cause a program to crash if multiple programs access the database at the same time.
This is not only happening when using Scalar but also when using

SELECT * FROM table

let table = Table("TProperties")
var all = [Row]()
do{
    all = Array(try db.prepare(table))
}catch{
     print("getSettings failed")
}

The reason behind it is the Generator type

extension Statement : GeneratorType {
    public func next() -> [Binding?]? {
        return try! step() ? Array(row) : nil
    }
}

My solution for it is the following change but i couldn't test yet if it is really working

extension Statement : GeneratorType {
    public func next() -> [Binding?]? {
        var result:[Binding?]?
        do{
            result = try step() ? Array(row) : nil
        }catch{
            result = nil
        }
        return result
        //return try! step() ? Array(row) : nil
    }
}
@blkbam
Copy link

blkbam commented Jun 24, 2016

I'm seeing the same thing occur. I'm crashing while iterating through the results. @Silve2611 did this change work for you?

@nickmshelley
Copy link
Collaborator

I'm hoping #413 will get merged at some point, which I think should take care of this. Unfortunately it's dependent on #451, but once that's through I'll try to get the error handling one to a good place.

@blkbam
Copy link

blkbam commented Jun 24, 2016

Just the change above alone to next() seems to do it in my short time testing however I'm sure the other changes are beneficial. I'll go through some more testing and take a look at the other PR's to see if I need to branch or hold off.

@Silve2611
Copy link
Author

Silve2611 commented Jun 26, 2016

Yes you are right. I had to modify the next() method to solve this. I helped myself by rewriting the statement function

extension Statement : GeneratorType {
     public func next() -> [Binding?]? {
        var result:[Binding?]?
        do{
            result = try step() ? Array(row) : nil
        }catch{
            result = nil
        }
        return result
        //this was the old code
        //return try! step() ? Array(row) : nil 
    }
}

@jberkel jberkel added this to the 0.11.2 milestone Dec 7, 2016
@jberkel jberkel modified the milestones: 0.11.2, 0.11.3 Dec 29, 2016
@jberkel jberkel modified the milestones: 0.11.3, 0.11.4 Mar 30, 2017
@jberkel
Copy link
Collaborator

jberkel commented Sep 30, 2017

fixed in 5a9b583

@jberkel jberkel closed this as completed Sep 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants