Skip to content

Difficulties and Tips

Jacob Schäfer edited this page Jul 26, 2022 · 28 revisions

Some Tips for Developers

  1. Github-Workflow First of all you have to create an issue to each change. This is split into a feature request or a bug request. While creating the issue we provide a template with further instructions. You have the possibility to tag the issue or to assign somebody to this issue. After creating the issue you have to link a branch to it. The default branches "develop" and "master" are protected. This means that you are only able to commit code to a feature (or bug)- Branch. Use this naming-convention: feature/GH-{issue-nr.}-{issue-short-title} or bugfix/GH-{issue-nr.}-{issue-short-title}.

    After pushing your code to the specific branch and resolving your issue you will merge this branch to the development branch. Create a self-describing pull request. To merge the branch your PR will have to fulfill two requirements:
  • Another person has to review your code
  • Every test (CI) has to be green
  1. Generated Squeak We explored automatically generating all messages which can be sent and received by TDLib via a C# project. Our progress can be seen here. Naming schemes still need to be adapted to comply with idiomatic squeak. We decided against including the code at that time as we had to setup initial concerns such as authorization. Now that this project gained some traction and more features future groups may decide there is worth in generating all classes.

  2. SAR File generation SAR files are generated by the CI pipeline. A pre-release is created on each commit on develop and a release on each commit on master.

  3. Multithreading In general you would use a separate thread which runs in the background and received new messages from TDLib. FFI only supports one thread, so we had to use the processor yield function to switch between normal program execution and stopping the execution for a not noticeable amount of time to fetch new messages.

In general, you should also use proper thread management tools like Semaphores and Mutexes. Occasionally, there can be hard-to-reproduce, hard-to-recognize and hard-to-fix bugs, that are most likely related to switching threads with bad timing. However, those bugs are infrequent, mostly due to the fact that there is no parallelism but only concurrency (i.e. only one thread can be active at a time).


Error Handling

Some errors we encountered frequently

  • external module not found: Your tdlib file might not be downloaded completely or have the wrong name. Also try restarting Squeak. If none of that works try building the library yourself with info's from here (programming language must be C).
  • errors with ExternalLibraryFunction or other FFI-Classes: Your FFI-Version might not be supported. If you installed FFI by Squeak starting configuration or by the wrong command look in our setup guide.
  • Segfault when reopening the image: Try deleting the current tdlib file. Now the image should open with some error message. Abandon it. Now you can safely put the tdlib back at its place or download it again. This does not happen if you close Telegram before closing the image.
  • phone number is not accepted: You can only log in some finite amount of times with the same phone each day. Try using a different phone number or telegram's testing data center supported by TCTTestCore. Also consider taking a break ;)
  • CI pipeline times out: This is probably due to authentication failures in the tests that use TDLib. Try debugging the issue by logging all TDLib events.

The last resort

When everything else has failed you,
and your friends can't reproduce, too,
when images crash for no reason,
you need to get rid of the treason,
try running this last piece of magic,
for Squeaks object clean-up is tragic.
 
An ancient HPI proverb

TCCCore allSubInstances do: [:e | (e respondsTo: #terminate) ifTrue: [e terminate] ifFalse: [e freeClient. e becomeForward: nil]]. TCUTelegram allInstancesDo: [:t | t delete]

A warning for developers

In commit bc4b05395ea1db6c49034960a23c81a03cf2e266 we split the -Tests package into multiple smaller packages. This change will most likely result in hard to fix conflicts and you should proceed with caution (and maybe a second image) when checking out commits from before that commit. Same goes for switching from before-bc4b05395ea1db6c49034960a23c81a03cf2e266 to after-bc4b05395ea1db6c49034960a23c81a03cf2e266 commits.


Mac Setup Guide (unofficial)

We aimed for providing a stable Version of TelegramClient in Squeak for Ubuntu, Windows and MacOS, but had lots of difficulties under MacOS and decided to not provide official support for Mac as we have limited resources available. However, part of our team did fully develop on Mac. We found the following workarounds:

  • Absolute paths are needed for FFI and tdlib to be able to write files under MacOS. We didn't find the root cause of that, but now absolute paths are created and used by default.
  • external module not found is the default under MacOS. To solve the issue, edit /Contents/Info.plist and set SqueakPluginsBuiltInOrLocalOnly to false. This allows Squeak to access the library
  • When squeak quits unexpectedly, undo the change in the info.plist, open squeak, abandon the debugger and redo the plist change again. It might also be a good idea to write a script that does that for you

With these two tips, Telegram runs stable on our machines. However, do proceed with caution and on your own risk.