Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. One commit ago, Dart code worked just fine

One commit ago, Dart code worked just fine

Scheduled Pinned Locked Moved The Lounge
javascriptdatabasesqlitehostingcloud
13 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Afzaal Ahmad Zeeshan

    Ever happened to you that everything worked just fine for you, you take a back up, make changes and it refuses to work as it is intended to? I am currently working on a Flutter app, which worked just perfectly! I committed the recent changes,

    $ git log -1
    commit 6441c90ee1c010362eb81740184fb50d900b46a1 (HEAD -> master, gitlab/master)
    Author: Afzaal Ahmad Zeeshan
    Date: Thu Jan 30 02:49:38 2020 +0500

    Contacts and lists now showing the phone numbers are showing too.

    The "past me" is telling me that database integration worked and SQLite receives all the records from the device for app usage. That is where I paused the development last night and committed the changes. Today I just resumed the development, and voila. The most basic of the code happens to not work.

    var contacts = await ContactsService.getContacts();

    if(contacts.length == 0) {
    print("[INFO] Device does not have any contacts.");
    return;
    }

    print("[INFO] Loaded ${contacts.length} contacts, attempting to save...");
    var database = await $FloorAppDatabase.databaseBuilder(MyApp.dbName).build();

    List newContacts = [];

    contacts.forEach((contact) async {
    // This variable is a placeholder to support debugging the response from database.
    var _contact = await database.recipientDao.findRecipientById(contact.identifier);
    if(_contact == null) {
    // Save the contact.
    newContacts.add(Recipient(contact.identifier, contact.displayName));
    }
    });

    if(newContacts.length > 0) {
    await database.recipientDao.insertAllRecipients(newContacts);
    print("[INFO] Added ${newContacts.length} contacts.");
    }

    The code attempts to save the contacts from a device to a device-only database. The _contact is always null, newContacts always gets a new element for contact (since there is no record in the database). But as soon as it hits the if(newContacts.length > 0) { line, the length of the array drops to zero. There isn't any closure (Dart is JavaScript of Google) in action, awaits are applied just fine to pause the execution at IO-bound tasks, but still, it simply refuses to work. Interesting thing is that this is the same code I committed last night! :laugh:

    The shit I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem ~! Firewall !~

    M Offline
    M Offline
    Mark_Wallace
    wrote on last edited by
    #4

    Just flag it: "Won't fix: works on my machine sometimes".

    I wanna be a eunuchs developer! Pass me a bread knife!

    1 Reply Last reply
    0
    • A Afzaal Ahmad Zeeshan

      Ever happened to you that everything worked just fine for you, you take a back up, make changes and it refuses to work as it is intended to? I am currently working on a Flutter app, which worked just perfectly! I committed the recent changes,

      $ git log -1
      commit 6441c90ee1c010362eb81740184fb50d900b46a1 (HEAD -> master, gitlab/master)
      Author: Afzaal Ahmad Zeeshan
      Date: Thu Jan 30 02:49:38 2020 +0500

      Contacts and lists now showing the phone numbers are showing too.

      The "past me" is telling me that database integration worked and SQLite receives all the records from the device for app usage. That is where I paused the development last night and committed the changes. Today I just resumed the development, and voila. The most basic of the code happens to not work.

      var contacts = await ContactsService.getContacts();

      if(contacts.length == 0) {
      print("[INFO] Device does not have any contacts.");
      return;
      }

      print("[INFO] Loaded ${contacts.length} contacts, attempting to save...");
      var database = await $FloorAppDatabase.databaseBuilder(MyApp.dbName).build();

      List newContacts = [];

      contacts.forEach((contact) async {
      // This variable is a placeholder to support debugging the response from database.
      var _contact = await database.recipientDao.findRecipientById(contact.identifier);
      if(_contact == null) {
      // Save the contact.
      newContacts.add(Recipient(contact.identifier, contact.displayName));
      }
      });

      if(newContacts.length > 0) {
      await database.recipientDao.insertAllRecipients(newContacts);
      print("[INFO] Added ${newContacts.length} contacts.");
      }

      The code attempts to save the contacts from a device to a device-only database. The _contact is always null, newContacts always gets a new element for contact (since there is no record in the database). But as soon as it hits the if(newContacts.length > 0) { line, the length of the array drops to zero. There isn't any closure (Dart is JavaScript of Google) in action, awaits are applied just fine to pause the execution at IO-bound tasks, but still, it simply refuses to work. Interesting thing is that this is the same code I committed last night! :laugh:

      The shit I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem ~! Firewall !~

      J Offline
      J Offline
      Jon McKee
      wrote on last edited by
      #5

      contacts.forEach((contact) async {
      // This variable is a placeholder to support debugging the response from database.
      var _contact = await database.recipientDao.findRecipientById(contact.identifier);
      if(_contact == null) {
      // Save the contact.
      newContacts.add(Recipient(contact.identifier, contact.displayName));
      }
      });

      if(newContacts.length > 0) {

      Never used Dart before, but everything in my being is telling me that looks dangerous if forEach isn't a blocking function. Some quick googling tells me you may want to try Future.forEach.

      A 1 Reply Last reply
      0
      • A Afzaal Ahmad Zeeshan

        Ever happened to you that everything worked just fine for you, you take a back up, make changes and it refuses to work as it is intended to? I am currently working on a Flutter app, which worked just perfectly! I committed the recent changes,

        $ git log -1
        commit 6441c90ee1c010362eb81740184fb50d900b46a1 (HEAD -> master, gitlab/master)
        Author: Afzaal Ahmad Zeeshan
        Date: Thu Jan 30 02:49:38 2020 +0500

        Contacts and lists now showing the phone numbers are showing too.

        The "past me" is telling me that database integration worked and SQLite receives all the records from the device for app usage. That is where I paused the development last night and committed the changes. Today I just resumed the development, and voila. The most basic of the code happens to not work.

        var contacts = await ContactsService.getContacts();

        if(contacts.length == 0) {
        print("[INFO] Device does not have any contacts.");
        return;
        }

        print("[INFO] Loaded ${contacts.length} contacts, attempting to save...");
        var database = await $FloorAppDatabase.databaseBuilder(MyApp.dbName).build();

        List newContacts = [];

        contacts.forEach((contact) async {
        // This variable is a placeholder to support debugging the response from database.
        var _contact = await database.recipientDao.findRecipientById(contact.identifier);
        if(_contact == null) {
        // Save the contact.
        newContacts.add(Recipient(contact.identifier, contact.displayName));
        }
        });

        if(newContacts.length > 0) {
        await database.recipientDao.insertAllRecipients(newContacts);
        print("[INFO] Added ${newContacts.length} contacts.");
        }

        The code attempts to save the contacts from a device to a device-only database. The _contact is always null, newContacts always gets a new element for contact (since there is no record in the database). But as soon as it hits the if(newContacts.length > 0) { line, the length of the array drops to zero. There isn't any closure (Dart is JavaScript of Google) in action, awaits are applied just fine to pause the execution at IO-bound tasks, but still, it simply refuses to work. Interesting thing is that this is the same code I committed last night! :laugh:

        The shit I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem ~! Firewall !~

        H Offline
        H Offline
        honey the codewitch
        wrote on last edited by
        #6

        Afzaal Ahmad Zeeshan wrote:

        Interesting thing is that this is the same code I committed last night!

        The fact that it didn't work before and did work now would seriously concern me. Whoops I understood your post backward Anyway, what I would consider is that your environment changed. See if there were any other commits or changes to the server?

        Real programmers use butterflies

        A 1 Reply Last reply
        0
        • A Afzaal Ahmad Zeeshan

          Ever happened to you that everything worked just fine for you, you take a back up, make changes and it refuses to work as it is intended to? I am currently working on a Flutter app, which worked just perfectly! I committed the recent changes,

          $ git log -1
          commit 6441c90ee1c010362eb81740184fb50d900b46a1 (HEAD -> master, gitlab/master)
          Author: Afzaal Ahmad Zeeshan
          Date: Thu Jan 30 02:49:38 2020 +0500

          Contacts and lists now showing the phone numbers are showing too.

          The "past me" is telling me that database integration worked and SQLite receives all the records from the device for app usage. That is where I paused the development last night and committed the changes. Today I just resumed the development, and voila. The most basic of the code happens to not work.

          var contacts = await ContactsService.getContacts();

          if(contacts.length == 0) {
          print("[INFO] Device does not have any contacts.");
          return;
          }

          print("[INFO] Loaded ${contacts.length} contacts, attempting to save...");
          var database = await $FloorAppDatabase.databaseBuilder(MyApp.dbName).build();

          List newContacts = [];

          contacts.forEach((contact) async {
          // This variable is a placeholder to support debugging the response from database.
          var _contact = await database.recipientDao.findRecipientById(contact.identifier);
          if(_contact == null) {
          // Save the contact.
          newContacts.add(Recipient(contact.identifier, contact.displayName));
          }
          });

          if(newContacts.length > 0) {
          await database.recipientDao.insertAllRecipients(newContacts);
          print("[INFO] Added ${newContacts.length} contacts.");
          }

          The code attempts to save the contacts from a device to a device-only database. The _contact is always null, newContacts always gets a new element for contact (since there is no record in the database). But as soon as it hits the if(newContacts.length > 0) { line, the length of the array drops to zero. There isn't any closure (Dart is JavaScript of Google) in action, awaits are applied just fine to pause the execution at IO-bound tasks, but still, it simply refuses to work. Interesting thing is that this is the same code I committed last night! :laugh:

          The shit I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem ~! Firewall !~

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #7

          No, no, that won't do. The usual complaint in the forum is that it worked yesterday, and nothing changed and it just stopped working. You can't just admit you broke it like that.

          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

          A 1 Reply Last reply
          0
          • J Jon McKee

            contacts.forEach((contact) async {
            // This variable is a placeholder to support debugging the response from database.
            var _contact = await database.recipientDao.findRecipientById(contact.identifier);
            if(_contact == null) {
            // Save the contact.
            newContacts.add(Recipient(contact.identifier, contact.displayName));
            }
            });

            if(newContacts.length > 0) {

            Never used Dart before, but everything in my being is telling me that looks dangerous if forEach isn't a blocking function. Some quick googling tells me you may want to try Future.forEach.

            A Offline
            A Offline
            Afzaal Ahmad Zeeshan
            wrote on last edited by
            #8

            Yep, you're right. What I am thinking about this is something like:

            Future processContacts(List contacts) async {
            for (var contact in contacts) {
            if(await database.recipientDao.findRecipientById(contact.identifier) == null) {
            // rest of the async code.
            }
            }
            }

            Future.forEach follows the similar approach to call the function that returns a Future, and await on it internally. Who knows, if I change the code to this approach, the problem goes away. :confused:

            The shit I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem ~! Firewall !~

            J 1 Reply Last reply
            0
            • R raddevus

              Afzaal Ahmad Zeeshan wrote:

              Ever happened to you that everything worked just fine for you, you take a back up, make changes and it refuses to work as it is intended to?

              Today after lunch. Very annoying.

              Afzaal Ahmad Zeeshan wrote:

              Interesting thing is that this is the same code I committed last night!

              I feel your pain. :) My code hasn't changed but now it fails to build. There's a transform script working on the app.config and the transform script (created by another dev) is failing all of a sudden. So, now instead of focusing on my code I have to figure out why the transform script is failing. I'm fixing the _hammer_ so I can nail the boards together. argh!! :|

              A Offline
              A Offline
              Afzaal Ahmad Zeeshan
              wrote on last edited by
              #9

              Quote:

              So, now instead of focusing on my code I have to figure out why the transform script is failing.

              True, such as a code-block it is. I have personally felt that among all the open-source frameworks, Flutter has the most open issues on GitHub. And these issues are not going anywhere. [Issues · flutter/flutter · GitHub](https://github.com/flutter/flutter/issues) Even if I don't mess up with anything, Google would update something and it just wouldn't work.

              The shit I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem ~! Firewall !~

              1 Reply Last reply
              0
              • H honey the codewitch

                Afzaal Ahmad Zeeshan wrote:

                Interesting thing is that this is the same code I committed last night!

                The fact that it didn't work before and did work now would seriously concern me. Whoops I understood your post backward Anyway, what I would consider is that your environment changed. See if there were any other commits or changes to the server?

                Real programmers use butterflies

                A Offline
                A Offline
                Afzaal Ahmad Zeeshan
                wrote on last edited by
                #10

                Quote:

                what I would consider is that your environment changed

                Nope, it is all same. The file is just 50 lines of code and using the [tip of Jon](https://www.codeproject.com/Lounge.aspx?fid=1159&df=90&mpp=25&sort=Position&spc=Relaxed&select=5695410&tid=5695372), I am considering a rewrite for this service, most probably that would spot any bugs if there are in my code. A big problem with Flutter is that it too often requires a flutter clean to remove the clutter, most problems were solved that way, but not this.

                The shit I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem ~! Firewall !~

                1 Reply Last reply
                0
                • L Lost User

                  No, no, that won't do. The usual complaint in the forum is that it worked yesterday, and nothing changed and it just stopped working. You can't just admit you broke it like that.

                  Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                  A Offline
                  A Offline
                  Afzaal Ahmad Zeeshan
                  wrote on last edited by
                  #11

                  Quote:

                  is that it worked yesterday, and nothing changed and it just stopped working.

                  Not yesterday, just one commit ago. Nothing changed, restarted the emulators to try everything with fresh app installation and it stopped working. I did a hard reset on my Git, but still the same. :sigh: The take away is, always test the code from the beginning and then commit. Sadly, I did not have the tests written to verify these services (contacts storage and database) so this is what I need to work on.

                  The shit I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem ~! Firewall !~

                  L 1 Reply Last reply
                  0
                  • A Afzaal Ahmad Zeeshan

                    Quote:

                    is that it worked yesterday, and nothing changed and it just stopped working.

                    Not yesterday, just one commit ago. Nothing changed, restarted the emulators to try everything with fresh app installation and it stopped working. I did a hard reset on my Git, but still the same. :sigh: The take away is, always test the code from the beginning and then commit. Sadly, I did not have the tests written to verify these services (contacts storage and database) so this is what I need to work on.

                    The shit I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem ~! Firewall !~

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #12

                    Afzaal Ahmad Zeeshan wrote:

                    Nothing changed

                    Exactly what I wanted to hear :D Yes, cherry picking, and not meant to be taken too seriously.

                    Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                    1 Reply Last reply
                    0
                    • A Afzaal Ahmad Zeeshan

                      Yep, you're right. What I am thinking about this is something like:

                      Future processContacts(List contacts) async {
                      for (var contact in contacts) {
                      if(await database.recipientDao.findRecipientById(contact.identifier) == null) {
                      // rest of the async code.
                      }
                      }
                      }

                      Future.forEach follows the similar approach to call the function that returns a Future, and await on it internally. Who knows, if I change the code to this approach, the problem goes away. :confused:

                      The shit I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem ~! Firewall !~

                      J Offline
                      J Offline
                      Jon McKee
                      wrote on last edited by
                      #13

                      I don't know enough about Dart to say. It depends on what you're looking to accomplish. If you want sequential but non-blocking processing of the list, yea I think it should work as long as you await on that function. EDIT: Removed a sentence, been reading up on asynchronous stuff in Dart and it's the same as C# where it doesn't allow await inside of a non-async function.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups