Thread 13: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)

I think the error is coming from here but I don't know what is my problem 

    //validate the fields
    let error = validateField()
    if error != nil{
      // there is something wrong with the fields, show error message
      showError(error!)
    }
    else{
      //create celaned versions of the data
      let first_name = firstNameTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
      let last_name = lastNameTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
      let email = emailTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
      let password = passwordTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
      //create users
      Auth.auth().createUser(withEmail: email, password: password) { (result, err) in
        //check for errors
        if err != nil {
          //there was an error creating users
          self.showError("Error creating user")
        }
        else{
          //user create successfully, now store f and l name
          let db = Firestore.firestore()
          db.collection("users").addDocument(data: ["first_name":first_name, "last_name":last_name, "uid": result!.user.uid]) {(error) in
            if error != nil {
              //show error message
              self.showError("User name couldn't be save in database")
            }
          }
          //transition to home screen
          self.transtionToHome()
        }
      }
    }
    
  }
   
**and here is the error message:

```libsystem_kernel.dylib`__pthread_kill:**
  0x7fff70173004 <+0>: movl  $0x2000148, %eax     ; imm = 0x2000148 
  0x7fff70173009 <+5>: movq  %rcx, %r10
  0x7fff7017300c <+8>: syscall 
-> 0x7fff7017300e <+10>: jae  0x7fff70173018      ; <+20> Thread 14: "-[FBLPromise HTTPBody]: unrecognized selector sent to instance 0x6000005ad8f0"
  0x7fff70173010 <+12>: movq  %rax, %rdi
  0x7fff70173013 <+15>: jmp  0x7fff7016d1c5      ; cerror_nocancel
  0x7fff70173018 <+20>: retq  
  0x7fff70173019 <+21>: nop   
  0x7fff7017301a <+22>: nop   
  0x7fff7017301b <+23>: nop   
Answered by Claude31 in 731647022

If you do not find the line, add some print statements in places, to see where it crashes:

    // validate the fields
    let error = validateField()
    print("#0")
    if error != nil{
      // there is something wrong with the fields, show error message
      showError(error!)
    } else {
      //create celaned versions of the data
      let first_name = firstNameTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
      let last_name = lastNameTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
      let email = emailTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
      let password = passwordTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
      // create users
      print("#1")
      Auth.auth().createUser(withEmail: email, password: password) { (result, err) in
      print("#2")
        // check for errors
        if err != nil {
          // there was an error creating users
          print("#3")
          self.showError("Error creating user")
        } else {
          // user create successfully, now store f and l name
          print("#4")
          let db = Firestore.firestore()
          print("#5")
          db.collection("users").addDocument(data: ["first_name":first_name, "last_name":last_name, "uid": result!.user.uid]) {(error) in
            if error != nil {
              //show error message
              print("#6")
              self.showError("User name couldn't be save in database")
            }
          }
          // transition to home screen
         print("#7")
          self.transtionToHome()
         print("#8")
        }
      }
    }
    
  }

And show exactly what you get in console log.

and when i click Sign Up button it doesn't do anything now :( it used to will go to next screen

Where is this signIn in your code ?

Please show all the needed code. Crash may not come from what you show.

Which line causes the crash ?

You should also test for result != nil.

if err != nil || result == nil { }

When you post code, please post the code, using code formatter, not a screen copy.

Which line number ?

1.     //validate the fields
2.     let error = validateField()
3.     if error != nil {
4.       // there is something wrong with the fields, show error message
5.       showError(error!)
6.     } else {
7.       //create celaned versions of the data
8.       let first_name = firstNameTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
9.       let last_name = lastNameTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
10.       let email = emailTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
11.       let password = passwordTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
12.       //create users
13.       Auth.auth().createUser(withEmail: email, password: password) { (result, err) in
14.         //check for errors
15.         if err != nil {
16.           //there was an error creating users
17.           self.showError("Error creating user")
18.         }
19.         else{
20.           //user create successfully, now store f and l name
21.           let db = Firestore.firestore()
22.           db.collection("users").addDocument(data: ["first_name":first_name, "last_name":last_name, "uid": result!.user.uid]) {(error) in
23.             if error != nil {
24.               //show error message
25.               self.showError("User name couldn't be save in database")
26.             }
27.           }
28.           //transition to home screen
29.           self.transtionToHome()
30.         }
31.       }
32.     }
33.     
34.   }

and when i click Sign Up button it doesn't do anything now :( it used to will go to next screen

Accepted Answer

If you do not find the line, add some print statements in places, to see where it crashes:

    // validate the fields
    let error = validateField()
    print("#0")
    if error != nil{
      // there is something wrong with the fields, show error message
      showError(error!)
    } else {
      //create celaned versions of the data
      let first_name = firstNameTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
      let last_name = lastNameTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
      let email = emailTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
      let password = passwordTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
      // create users
      print("#1")
      Auth.auth().createUser(withEmail: email, password: password) { (result, err) in
      print("#2")
        // check for errors
        if err != nil {
          // there was an error creating users
          print("#3")
          self.showError("Error creating user")
        } else {
          // user create successfully, now store f and l name
          print("#4")
          let db = Firestore.firestore()
          print("#5")
          db.collection("users").addDocument(data: ["first_name":first_name, "last_name":last_name, "uid": result!.user.uid]) {(error) in
            if error != nil {
              //show error message
              print("#6")
              self.showError("User name couldn't be save in database")
            }
          }
          // transition to home screen
         print("#7")
          self.transtionToHome()
         print("#8")
        }
      }
    }
    
  }

And show exactly what you get in console log.

and when i click Sign Up button it doesn't do anything now :( it used to will go to next screen

Where is this signIn in your code ?

Please show all the needed code. Crash may not come from what you show.

Thread 13: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
 
 
Q