Skip to content

Incorrect data in callback [email protected] #420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
szujak opened this issue May 28, 2025 · 4 comments
Open

Incorrect data in callback [email protected] #420

szujak opened this issue May 28, 2025 · 4 comments

Comments

@szujak
Copy link

szujak commented May 28, 2025

Hello,

After upgrading to 0.22.1 I noticed that there is an issue with returning data from ReactNativeBlobUtil.df on windows.

I'm calling this method const availableDiskSpace = await ReactNativeBlobUtil.fs.df(); but instead of information about storage the error is thrown with message {"code":"EUNSPECIFIED"}

After checking the df method code I noticed that on windows the storage info is populated in err argument

function df(): Promise<{ free: number, total: number }> {
    return new Promise((resolve, reject) => {
        ReactNativeBlobUtil.df((err, stat) => {
            console.log(err, stat) // the err argument contains [{"free": 123, "total": 1234}] and stat is undefined
            if (err)
                reject(addCode('EUNSPECIFIED', new Error(err)));
            else
                resolve(stat);
        });
    });
}

Calling the same method on android works fine - err is null and stat contains storage info

@szujak
Copy link
Author

szujak commented May 28, 2025

Also the data format looks different on Android and Windows

Android (object):
{"external_free": "51120422912", "external_total": "52655943680", "internal_free": "51120422912", "internal_total": "52655943680"}

Windows (array with object):
[{"free": 337609101312, "total": 1023285473280}]

@szujak
Copy link
Author

szujak commented May 28, 2025

For now I adjusted winrt::fire_and_forget ReactNativeBlobUtil::df function to

winrt::fire_and_forget ReactNativeBlobUtil::df(
    std::function<void(::React::JSValue, ::React::JSValue)> callback) noexcept
{ 
        try
        {
            auto localFolder = winrt::Windows::Storage::ApplicationData::Current().LocalFolder();
            auto properties{ co_await localFolder.Properties().RetrievePropertiesAsync({L"System.FreeSpace", L"System.Capacity"}) };

            winrt::Microsoft::ReactNative::JSValueObject result;
            result["free"] = winrt::unbox_value<uint64_t>(properties.Lookup(L"System.FreeSpace"));
            result["total"] = winrt::unbox_value<uint64_t>(properties.Lookup(L"System.Capacity"));

            callback(nullptr, ::React::JSValueObject(std::move(result)));
        }
        catch (...)
        {
            winrt::Microsoft::ReactNative::JSValueObject error;
            error["error"] = "Failed to get storage usage.";

            callback(::React::JSValueObject(std::move(error)), nullptr);
        }
}

@anupriya13
Copy link

Yes, this was generated as per the codegen Spec file which had std::function<void(::React::JSValueArray)> callback. @RonRadtke can confirm which one we should follow?
JS to C++ via turbomodules

+df: (callback: (value: Array<any>) => void) => void;

@RonRadtke
Copy link
Owner

I would say the codegen ist wrong here. It should be a plain object, no need for wrapping it in an array.
But should check that iOS is doing the same then. Sadly enough we can't use the exact same keys for Android / win / iOS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants