Git Product home page Git Product logo

Comments (3)

thgreasi avatar thgreasi commented on August 19, 2024

Hi, can you provide an example with the arguments that you provide to the .create() call?
I would be interested at seeing the invalid name that causes this issue.

from balena-sdk.

bartversluijs avatar bartversluijs commented on August 19, 2024

Hi,

I used a colon (:) in the name, which caused the fail. So something like fleet:test.

from balena-sdk.

thgreasi avatar thgreasi commented on August 19, 2024

Hi @bartversluijs,
It seems that this fell through the cracks of my inbox...

I think the issue that you are facing is that you are not waiting for the returned promise to resolve.

This causes the auth.isLoggedIn() function to always state true, which isn't the case.

auth.isLoggedIn() returns a promise, which if used directly in an if statement could be confused with a true boolean, but if you console.log(sdk.auth.isLoggedIn()) your console should print Promise {<pending>}.
You can use .then() or await inside async functions. Let me also point you to our test cases that make sure that the returned promise resolves to false when there is no logged in user:

describe('balena.auth.isLoggedIn()', () => {
it('should eventually be false', async function () {
expect(await balena.auth.isLoggedIn()).to.be.false;
});
});

Similarly when calling application.create() with invalid parameters, the function will not throw synchronously (especially since the name validation is done by our backend), but it will instead return a promise that will be rejected. You can handle that case by either using .catch((err) => { console.log(err) }) or using try catch with await like:

try {
    const fleet = await sdk.models.application.create({
        deviceType: 'raspberrypi3',
        name: 'fleet:test',
        organization: 'thgreasinomembersorg'
    });
    console.log(fleet);
} catch (err) {
    console.error(err);
}

which should log something like:

BalenaRequestError: Request error: App name may only contain [a-zA-Z0-9_-].

Given that we do have test cases for these I will close the issue for now, but feel free to re-open or ask for further help here or in a new issue.

Kind regards,
Thodoris

from balena-sdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.