Astal icon indicating copy to clipboard operation
Astal copied to clipboard

How to access errors thrown by AstalBluetooth.Device.connect_device

Open Quadrubo opened this issue 9 months ago • 1 comments

Have you read through the documentation?

Describe your question I am using the Typescript SDK with GTK4 and am trying to write my Bluetooth module. AstalBluetooth.Device.connect_device states that there are possible errors: "NotReady, Failed, InProgress, AlreadyConnected".

How do I access those errors from typescript? I want to show an error message when the connection failed.

Describe what have you tried so far

I tried printing the properties and looking for attributes on them. Source just seems to return the device and I couldn't find anything in result (BTW, is there a way to use the VSCode debugger? Couldn't get it to work using AGS).

 device.connect_device((source, result) => {
          print(source);
          print(result);
        });

I also tried wrapping it in a try-catch but this never throws.

try {
          device.connect_device((source, result) => {
            print(source);
            print(result);
          });
        } catch (error) {
          print(error);
        }

Thank you for the help and sorry if this is a simple question :)

Quadrubo avatar Mar 22 '25 13:03 Quadrubo

Connect device is an async method. You have to use device.connect_device_finish(res) to access the return value and catch any errors. e.g.

device.connect_device((_, res) => {
    try {
       device.connect_device_finish(res);
    } catch (e) {
        console.error(e);
    }
});

soramanew avatar Mar 29 '25 07:03 soramanew